Skip to content

Commit

Permalink
Merge PR #43517
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Nov 25, 2021
1 parent 35983b1 commit 38cb561
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Ignore persisted in-memory records when merging target lists.

*Kevin Sjöberg*

* Fix regression bug that caused ignoring additional conditions for preloading has_many-through relations.

Fixes #43132
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def merge_target_lists(persisted, memory)
end
end

persisted + memory
persisted + memory.reject(&:persisted?)
end

def _create_record(attributes, raise = false, &block)
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,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
end

class OverridingAssociationsTest < ActiveRecord::TestCase
Expand Down

0 comments on commit 38cb561

Please sign in to comment.