Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure Model.scoped adds type conditions for STI models

  • Loading branch information...
commit f3741506981d8d4aafb28066f5a3a0509a4da846 1 parent c6258ee
@lifo lifo authored
View
1  activerecord/lib/active_record/named_scope.rb
@@ -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)
View
25 activerecord/lib/active_record/relation.rb
@@ -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)
View
2  activerecord/test/cases/finder_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.