From a8827cb9afdf122c003fbff1bfcc28bda2994d04 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 5 Sep 2014 04:27:54 -0700 Subject: Fixed regression with referencing polymorphic assoc in eager-load This is cased by 03118bc + 9b5d603. The first commit referenced the undefined local variable `column` when it should be using `reflection.type` as the lookup key. The second commit changed `build_arel` to not modify the `bind_values` in- place so we need to combine the arel's `bind_values` with the relation's when building the SQL. Fixes #16591 Related #15821 / #15892 / 7aeca50 --- activerecord/test/cases/associations/eager_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 21912fdf0f..b852bd3536 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1290,4 +1290,14 @@ class EagerAssociationTest < ActiveRecord::TestCase david = Author.where(id: "1").eager_load(:readonly_comments).first! assert david.readonly_comments.first.readonly? end + + test "preloading a polymorphic association with references to the associated table" do + post = Post.includes(:tags).references(:tags).where('tags.name = ?', 'General').first + assert_equal posts(:welcome), post + end + + test "eager-loading a polymorphic association with references to the associated table" do + post = Post.eager_load(:tags).where('tags.name = ?', 'General').first + assert_equal posts(:welcome), post + end end -- cgit v1.2.3