-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Do not consolidate persisted in-memory records #43517
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -289,6 +289,16 @@ def test_reset_unloads_target | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert_not_predicate david.posts, :loaded? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert_not_predicate david.posts, :loaded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_target_merging_ignores_persisted_in_memory_records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
david = authors(:david) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert david.thinking_posts.include?(posts(:thinking)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
david.thinking_posts.create!(title: "Something else entirely", body: "Does not matter.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert_equal 1, david.thinking_posts.size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assert_equal 1, david.thinking_posts.to_a.size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+293
to
+301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Does this also work? (Mostly just want to make sure I've understood the issue correctly.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, correct. That test case would pass as well. 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth adding it as an additional test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. That behaviour was already present prior to my change, so I would expect things to blow up left and right if that part broke. But if anyone feel strongly about it, I don't mind adding another test case. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class OverridingAssociationsTest < ActiveRecord::TestCase | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
If the issue is that
persisted
andmemory
have the same objects, is this a better fix?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.
why don't just do
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.
🤦 yeah that
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.
The issue isn't that
persisted
andmemory
contains the same records. In fact, that is to be expected.merge_target_lists
already handles duplicates. The issue is that thememory
collection may contain persisted records that are not present in thepersisted
collection. These records are currently being included even though they shouldn't. Thepersisted
collection is already up-to-date, so if there are records in memory that are persisted but not part ofpersisted
they are invalid (e.g., violating the association scope).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.
@kevinsjoberg I think the documentation at the beginning of this method should also be updated to reflect this change.