Skip to content

Commit

Permalink
Fix generated WHERE IN query for named scopes. [#583 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
phallstrom authored and lifo committed Aug 21, 2008
1 parent a970f91 commit 49c0e1e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/named_scope_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions activerecord/test/models/developer.rb
Expand Up @@ -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

Expand Down

0 comments on commit 49c0e1e

Please sign in to comment.