提交 5153c0c2 编写于 作者: K Kasper Timm Hansen 提交者: GitHub

Merge pull request #29679 from kamipo/add_test_case_for_27724

Add a test case for overwriting existing condition on associations
......@@ -946,6 +946,13 @@ def test_can_update_through_association
end
end
def test_has_many_through_polymorphic_with_rewhere
post = TaggedPost.create!(title: "Tagged", body: "Post")
tag = post.tags.create!(name: "Tag")
assert_equal [tag], TaggedPost.preload(:tags).last.tags
assert_equal [tag], TaggedPost.eager_load(:tags).last.tags
end
def test_has_many_through_polymorphic_with_primary_key_option
assert_equal [categories(:general)], authors(:david).essay_categories
......
......@@ -199,6 +199,11 @@ class FirstPost < ActiveRecord::Base
has_one :comment, foreign_key: :post_id
end
class TaggedPost < Post
has_many :taggings, -> { rewhere(taggable_type: "TaggedPost") }, as: :taggable
has_many :tags, through: :taggings
end
class PostWithDefaultInclude < ActiveRecord::Base
self.inheritance_column = :disabled
self.table_name = "posts"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册