提交 f3741506 编写于 作者: P Pratik Naik

Ensure Model.scoped adds type conditions for STI models

上级 c6258ee3
......@@ -28,6 +28,7 @@ def scoped(options = {}, &block)
else
if !scoped?(:find)
relation = arel_table
relation = relation.where(type_condition) if finder_needs_type_condition?
else
relation = construct_finder_arel
include_associations = scope(:find, :include)
......
......@@ -49,19 +49,22 @@ def on(join)
end
def joins(join, join_type = nil)
join = case join
when String
@relation.join(join)
when Hash, Array, Symbol
if @klass.send(:array_of_strings?, join)
@relation.join(join.join(' '))
else
@relation.join(@klass.send(:build_association_joins, join))
end
return self if join.blank?
join_relation = case join
when String
@relation.join(join)
when Hash, Array, Symbol
if @klass.send(:array_of_strings?, join)
@relation.join(join.join(' '))
else
@relation.join(join, join_type)
@relation.join(@klass.send(:build_association_joins, join))
end
else
@relation.join(join, join_type)
end
create_new_relation(join)
create_new_relation(join_relation)
end
def where(*args)
......
......@@ -291,7 +291,7 @@ def test_find_on_hash_conditions_with_hashed_table_name
end
def test_find_with_hash_conditions_on_joined_table
firms = Firm.all :joins => :account, :conditions => {:accounts => { :credit_limit => 50 }}
firms = Firm.joins(:account).where(:accounts => { :credit_limit => 50 })
assert_equal 1, firms.size
assert_equal companies(:first_firm), firms.first
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册