Skip to content
Browse files

Fix generated WHERE IN query for named scopes. [#583 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent a970f91 commit 49c0e1e594c95d7e8446ebabecc9147afa62de7d @phallstrom phallstrom committed with lifo Aug 21, 2008
View
2 activerecord/lib/active_record/base.rb
@@ -1750,7 +1750,7 @@ def all_attributes_exists?(attribute_names)
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
View
5 activerecord/test/cases/named_scope_test.rb
@@ -4,6 +4,7 @@
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 @@ def test_should_build_with_proxy_options_chained
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
View
2 activerecord/test/models/developer.rb
@@ -43,6 +43,8 @@ def find_least_recent
has_many :audit_logs
+ named_scope :jamises, :conditions => {:name => 'Jamis'}
+
validates_inclusion_of :salary, :in => 50000..200000
validates_length_of :name, :within => 3..20

0 comments on commit 49c0e1e

Please sign in to comment.
Something went wrong with that request. Please try again.