MONGOID-5900 Fix #pluck on associations#6068
Merged
jamis merged 1 commit intomongodb:9.0-stablefrom Nov 24, 2025
Merged
Conversation
* use the specialized implementation of pluck * use a custom pluck implementation * new file * incorporate Johnny's changes from mongodb#6044 * use same submodules as master * Make changes suggested by copilot review * rubocop appeasement * fix broken refactoring
Contributor
There was a problem hiding this comment.
Pull request overview
This PR backports bug fixes to the 9.0-stable branch for #pluck on associations (MONGOID-5900, MONGOID-5901). The implementation addresses three key issues: proper handling of localized fields with current locale settings, correct plucking from both loaded and unloaded association records, and proper resolution of field aliases.
- Extracts shared plucking logic into a new
Pluckablemodule to avoid code duplication - Updates
has_manyandembeds_manyassociations to properly delegatepluckoperations - Updates RuboCop configuration to set global complexity thresholds instead of inline suppressions
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/mongoid/pluckable.rb | New module extracting shared plucking functionality with methods for field preparation, document plucking, value extraction, and demongoization |
| lib/mongoid/contextual/mongo.rb | Refactored to use Pluckable module, simplifying the pluck implementation and removing duplicate logic |
| lib/mongoid/association/referenced/has_many/enumerable.rb | Added Pluckable module and implemented pluck method handling loaded/unloaded/added documents correctly |
| lib/mongoid/association/referenced/has_many/proxy.rb | Added pluck delegation to _target and changed def_delegator to def_delegators |
| lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb | Removed inline rubocop:disable comments for AbcSize metric |
| lib/mongoid/association/embedded/embeds_many/proxy.rb | Added pluck delegation using def_delegators and removed manual find method definition |
| lib/mongoid/traversable.rb | Removed inline rubocop:disable comments for AbcSize metric |
| .rubocop.yml | Added global thresholds for PerceivedComplexity, CyclomaticComplexity, and AbcSize metrics |
| spec/mongoid/association/referenced/has_many/enumerable_spec.rb | Comprehensive test coverage for pluck with localized fields, aliases, embedded documents, and fallbacks |
| spec/support/models/seo.rb | Added localized fields for testing: name and aliased desc/description |
| spec/support/models/passport.rb | Added localized aliased field bp/birthplace for testing |
| spec/support/models/product.rb | Added belongs_to :company association for testing |
| spec/support/models/company.rb | Added has_many :products association for testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
comandeo-mongo
approved these changes
Nov 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #6067 to 9.0-stable
This addresses a few bugs with the implementation of
#pluckon associations.Tests from #6044 (from @johnnyshields) are included in this PR (thank you, Johnny!).