diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 00:11:31 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-27 00:11:31 +0530 |
commit | f3741506981d8d4aafb28066f5a3a0509a4da846 (patch) | |
tree | e40919c45f5e6a0ffa8853b6eec4804c5c16df48 /activerecord | |
parent | c6258ee313653bc54e94e0008f1c098ed68aa3f4 (diff) | |
download | rails-f3741506981d8d4aafb28066f5a3a0509a4da846.tar.gz rails-f3741506981d8d4aafb28066f5a3a0509a4da846.tar.bz2 rails-f3741506981d8d4aafb28066f5a3a0509a4da846.zip |
Ensure Model.scoped adds type conditions for STI models
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 25 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 2 |
3 files changed, 16 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 38d54fa8ec..96d361093f 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -28,6 +28,7 @@ module ActiveRecord 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) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 853103a606..b6800b07b7 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -49,19 +49,22 @@ module ActiveRecord 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) diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 3de07797d4..57ce0eee61 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -291,7 +291,7 @@ class FinderTest < ActiveRecord::TestCase 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 |