MONGOID-5935 Fixed UnknownAttribute error with nested attributes#6155
Open
jamis wants to merge 1 commit into
Open
MONGOID-5935 Fixed UnknownAttribute error with nested attributes#6155jamis wants to merge 1 commit into
jamis wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Mongoid::Errors::UnknownAttribute raised during nested-attributes processing when _destroy is provided for an existing child document that is not currently part of the parent’s relation (notably when reparenting via nested attributes is enabled).
Changes:
- Update nested many-association handling to skip reparenting/update logic when the incoming nested attributes are destroy requests (
_destroy), preventing_destroyfrom being passed intoupdate_attributes. - Add regression specs for both
has_manyandhas_and_belongs_to_manyrelations ensuring_destroyon a non-related existing document does not raise and does not add the document to the relation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/mongoid/association/nested/many.rb |
Prevents _destroy payloads from flowing into reparenting/update paths for non-related existing documents. |
spec/mongoid/attributes/nested_spec.rb |
Adds coverage for destroy-on-non-related-document cases for has_many and HABTM nested attributes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This fixes the raised
Mongoid::Errors::UnknownAttributeerror when nested attributes include_destroy: truefor a child whose_idis not already in the parent's relation (e.g. a new parent receiving an existing child's_id).