diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-03-22 15:02:49 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-03-22 15:08:09 +0100 |
commit | c8edd4fda45bbc7c99beaaf2d53f4de59c3fac54 (patch) | |
tree | 6a6fd983c2590c53661d8e0f9e5612968ba28659 /activerecord/test | |
parent | 69599b63de927091faf1d804b6457f65014080d6 (diff) | |
download | rails-c8edd4fda45bbc7c99beaaf2d53f4de59c3fac54.tar.gz rails-c8edd4fda45bbc7c99beaaf2d53f4de59c3fac54.tar.bz2 rails-c8edd4fda45bbc7c99beaaf2d53f4de59c3fac54.zip |
do not reset associations when preloading twice.
Closes #9806.
As the `through_options` always contained `{:order=>nil}` the second time,
the preloader ran, the association was always reset. This patch only
adds the `:order` to the `through_options` if it is set.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 944f135153..490aafa86d 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1118,4 +1118,11 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_no_queries { assert_equal 2, author.comments_with_order_and_conditions.size } assert_no_queries { assert_equal 5, author.posts.size, "should not cache a subset of the association" } end + + test "preloading a through association twice does not reset it" do + members = Member.includes(current_membership: :club).includes(:club).to_a + assert_no_queries { + assert_equal 3, members.map(&:current_membership).map(&:club).size + } + end end |