diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-29 14:35:19 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-29 14:50:50 -0700 |
commit | af2c427c390b87ea20986f1e82b498068800d775 (patch) | |
tree | c1a451704b2bf00a2b976ed5e757ac3cf56cb6fa /activerecord/test/cases/associations | |
parent | ddb7be50e8a0946d29fbe66537f845b8369413b7 (diff) | |
download | rails-af2c427c390b87ea20986f1e82b498068800d775.tar.gz rails-af2c427c390b87ea20986f1e82b498068800d775.tar.bz2 rails-af2c427c390b87ea20986f1e82b498068800d775.zip |
Respect through association scopes when used with polymorphic
When the `source_type` option is passed to a has_many through, the
resulting `Reflection` will be an instance of `PolymorphicReflection`
and not `ThroughReflection`, meaning that it will ignore the scopes that
it needs to apply from the through reflections. This adds an additional
delegation call to remedy this. I've been finding the reflection code
completely impenetrable lately, it could use some major love.
Fixes #22726
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/join_model_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index c850875619..1d892a0956 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -363,6 +363,13 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase assert_equal posts(:welcome, :thinking).sort_by(&:id), tags(:general).tagged_posts.sort_by(&:id) end + def test_has_many_polymorphic_associations_merges_through_scope + Tag.has_many :null_taggings, -> { none }, class_name: :Tagging + Tag.has_many :null_tagged_posts, :through => :null_taggings, :source => 'taggable', :source_type => 'Post' + assert_equal [], tags(:general).null_tagged_posts + refute_equal [], tags(:general).tagged_posts + end + def test_eager_has_many_polymorphic_with_source_type tag_with_include = Tag.all.merge!(:includes => :tagged_posts).find(tags(:general).id) desired = posts(:welcome, :thinking) |