Skip to content

Conversation

@jamis
Copy link
Contributor

@jamis jamis commented Nov 21, 2025

Backport of #6067 to 9.0-stable

This addresses a few bugs with the implementation of #pluck on associations.

  1. It now respects localized fields, and the current localization settings.
  2. It now plucks loaded and unloaded records from the association.
  3. It now does the right thing when fields are referenced by an alias.

Tests from #6044 (from @johnnyshields) are included in this PR (thank you, Johnny!).

* 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
Copilot AI review requested due to automatic review settings November 21, 2025 15:53
@jamis jamis requested a review from a team as a code owner November 21, 2025 15:53
@jamis jamis requested a review from comandeo-mongo November 21, 2025 15:53
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Nov 21, 2025
Copilot finished reviewing on behalf of jamis November 21, 2025 15:57
Copy link
Contributor

Copilot AI left a 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 Pluckable module to avoid code duplication
  • Updates has_many and embeds_many associations to properly delegate pluck operations
  • 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.

@jamis jamis merged commit 2843c02 into mongodb:9.0-stable Nov 24, 2025
67 checks passed
@jamis jamis deleted the 5901-pluck-backport-9.0 branch November 24, 2025 22:41
@jamis jamis changed the title MONGOID-5900, MONGOID-5901 Fix #pluck on associations MONGOID-5900 Fix #pluck on associations Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug, with no new features or broken compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants