提交 01cffc37 编写于 作者: R Ryuta Kamizono

Allow `where` with through association to be expanded condition

上级 c65864cd
......@@ -86,6 +86,10 @@ def expand_from_hash(attributes, &block)
value = [value] unless value.is_a?(Array)
klass = PolymorphicArrayValue
end
elsif associated_table.through_association?
next associated_table.predicate_builder.expand_from_hash(
associated_table.association_join_foreign_key => value
)
end
klass ||= AssociationQueryValue
......
......@@ -55,6 +55,10 @@ def polymorphic_association?
reflection&.polymorphic?
end
def through_association?
reflection&.through_reflection?
end
def reflect_on_aggregation(aggregation_name)
klass&.reflect_on_aggregation(aggregation_name)
end
......
......@@ -25,6 +25,10 @@ def test_type_casting_nested_joins
assert_equal [comment], Comment.joins(post: :author).where(authors: { id: "2-foo" })
end
def test_where_with_through_association
assert_equal [authors(:david)], Author.joins(:comments).where(comments: comments(:greetings))
end
def test_type_cast_is_not_evaluated_at_relation_build_time
posts = nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册