提交 49c0e1e5 编写于 作者: P Philip Hallstrom 提交者: Pratik Naik

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

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 a970f916
......@@ -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
......
......@@ -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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册