diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-09-16 19:12:11 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-16 19:12:11 +0900 |
commit | 2df65b6fae6d5356ba783809a3c9a598f1539e3e (patch) | |
tree | 964f101258289ef39df15d8e9c5292e8ecab20b9 /activerecord/test | |
parent | a8c124ab8ced593462dc9347c2a1806b09c74f6f (diff) | |
parent | 9897f50ae77d5880bac292ac35873490669fc107 (diff) | |
download | rails-2df65b6fae6d5356ba783809a3c9a598f1539e3e.tar.gz rails-2df65b6fae6d5356ba783809a3c9a598f1539e3e.tar.bz2 rails-2df65b6fae6d5356ba783809a3c9a598f1539e3e.zip |
Merge pull request #33895 from faucct/bugfix/preload_multiple_instances_of_same_record
ActiveRecord::Associations::Preloader should preload all instances of the same record
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index d5573b6d02..442f4a93d4 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -71,6 +71,15 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase club1.members.sort_by(&:id) end + def test_preload_multiple_instances_of_the_same_record + club = Club.create!(name: "Aaron cool banana club") + Membership.create! club: club, member: Member.create!(name: "Aaron") + Membership.create! club: club, member: Member.create!(name: "Bob") + + preloaded_clubs = Club.joins(:memberships).preload(:membership).to_a + assert_no_queries { preloaded_clubs.each(&:membership) } + end + def test_ordered_has_many_through person_prime = Class.new(ActiveRecord::Base) do def self.name; "Person"; end |