-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5900 Fix #pluck on associations #6068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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!).