diff options
author | Philip Hallstrom <philip@pjkh.com> | 2008-08-21 16:08:42 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-08-21 16:11:28 +0100 |
commit | 49c0e1e594c95d7e8446ebabecc9147afa62de7d (patch) | |
tree | fc260ee34139101764af8005d4284e3b4b913652 /activerecord | |
parent | a970f916fb1e05376733e2d42d9bcc2b873af355 (diff) | |
download | rails-49c0e1e594c95d7e8446ebabecc9147afa62de7d.tar.gz rails-49c0e1e594c95d7e8446ebabecc9147afa62de7d.tar.bz2 rails-49c0e1e594c95d7e8446ebabecc9147afa62de7d.zip |
Fix generated WHERE IN query for named scopes. [#583 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/base.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 2 |
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5357255bad..15c6bc1b4a 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1750,7 +1750,7 @@ module ActiveRecord #:nodoc: def attribute_condition(argument) case argument when nil then "IS ?" - when Array, ActiveRecord::Associations::AssociationCollection then "IN (?)" + when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "IN (?)" when Range then "BETWEEN ? AND ?" else "= ?" end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 7cc51f5d68..db31ddb293 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -4,6 +4,7 @@ require 'models/topic' require 'models/comment' require 'models/reply' require 'models/author' +require 'models/developer' class NamedScopeTest < ActiveRecord::TestCase fixtures :posts, :authors, :topics, :comments, :author_addresses @@ -242,4 +243,8 @@ class NamedScopeTest < ActiveRecord::TestCase def test_find_all_should_behave_like_select assert_equal Topic.base.select(&:approved), Topic.base.find_all(&:approved) end + + def test_should_use_where_in_query_for_named_scope + assert_equal Developer.find_all_by_name('Jamis'), Developer.find_all_by_id(Developer.jamises) + end end diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 9f26cacdec..c08476f728 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -43,6 +43,8 @@ class Developer < ActiveRecord::Base has_many :audit_logs + named_scope :jamises, :conditions => {:name => 'Jamis'} + validates_inclusion_of :salary, :in => 50000..200000 validates_length_of :name, :within => 3..20 |