-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Preserve extra data in RelationshipTarget
with replace_related
(_with_difference
)
#19588
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
base: main
Are you sure you want to change the base?
Conversation
variable names and comments
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.
Good; thanks for the tests here. This is too tricky to be confident without them.
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.
Looks good to me! I would just like to see the dead code disappear.
On a side note, I'm not sure why replace_related_with_difference
needs the entities_to_relate
argument.
.insert_with_relationship_hook_mode(R::from(this), RelationshipHookMode::Skip); | ||
} | ||
}); | ||
|
||
if !entities_to_relate.is_empty() { | ||
if let Some(mut target) = self.get_mut::<R::RelationshipTarget>() { |
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.
Given the if
at line 244, this if let else
always branches on if let
.
.insert_with_relationship_hook_mode(R::from(this), RelationshipHookMode::Skip); | ||
} | ||
}); | ||
|
||
if !entities_to_relate.is_empty() { |
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.
I don't think this test is necessary.
Objective
The methods and commands
replace_related
andreplace_related_with_difference
may cause data stored at theRelationshipTarget
be lost when all original children are removed before new children are added.Part of #19589
Solution
Fix the issue, either by removing the old children after adding the new ones and not before (
replace_related_with_difference
) or by taking the wholeRelationshipTarget
to modify it, not only the inner collection (replace_related
).Testing
I added a new test asserting the data is kept. I also added a general test of these methods as they had none previously.