diff options
author | Nikita Sokolov <nikitasokolov@MacBook-Pro-Nikita.local> | 2018-09-16 10:57:08 +0300 |
---|---|---|
committer | Nikita Sokolov <nikitasokolov@MacBook-Pro-Nikita.local> | 2018-09-16 11:49:26 +0300 |
commit | 9897f50ae77d5880bac292ac35873490669fc107 (patch) | |
tree | f064d334900747fb15afc9dc90693289226830fb /activerecord | |
parent | 65bf046fd1c05405591b940e3b3cd718ca1edba1 (diff) | |
download | rails-9897f50ae77d5880bac292ac35873490669fc107.tar.gz rails-9897f50ae77d5880bac292ac35873490669fc107.tar.bz2 rails-9897f50ae77d5880bac292ac35873490669fc107.zip |
ActiveRecord::Associations::Preloader should preload all instances of the same record
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 5c2ac5b374..d4d1b2a282 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -88,7 +88,6 @@ module ActiveRecord if records.empty? [] else - records.uniq! Array.wrap(associations).flat_map { |association| preloaders_on association, records, preload_scope } 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 |