public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix generated WHERE IN query for named scopes. [#583 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Philip Hallstrom (author)
Thu Aug 21 08:08:42 -0700 2008
Tarmo Tänav (committer)
Sun Aug 24 09:41:51 -0700 2008
commit  2092f26edbd6de6d542a7bbd5b4dd30d5fd66ef4
tree    af118cd48cff4ee71b9e3440243201ecf5c3b092
parent  0048f558e69cfc2675552dd31ea773b2b8271e9b
...
1722
1723
1724
1725
 
1726
1727
1728
...
1722
1723
1724
 
1725
1726
1727
1728
0
@@ -1722,7 +1722,7 @@ module ActiveRecord #:nodoc:
0
         def attribute_condition(argument)
0
           case argument
0
             when nil   then "IS ?"
0
-            when Array, ActiveRecord::Associations::AssociationCollection then "IN (?)"
0
+            when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope then "IN (?)"
0
             when Range then "BETWEEN ? AND ?"
0
             else            "= ?"
0
           end
...
4
5
6
 
7
8
9
...
189
190
191
 
 
 
 
192
...
4
5
6
7
8
9
10
...
190
191
192
193
194
195
196
197
0
@@ -4,6 +4,7 @@ require 'models/topic'
0
 require 'models/comment'
0
 require 'models/reply'
0
 require 'models/author'
0
+require 'models/developer'
0
 
0
 class NamedScopeTest < ActiveRecord::TestCase
0
   fixtures :posts, :authors, :topics, :comments, :author_addresses
0
@@ -189,4 +190,8 @@ class NamedScopeTest < ActiveRecord::TestCase
0
   def test_find_all_should_behave_like_select
0
     assert_equal Topic.base.select(&:approved), Topic.base.find_all(&:approved)
0
   end
0
+
0
+  def test_should_use_where_in_query_for_named_scope
0
+    assert_equal Developer.find_all_by_name('Jamis'), Developer.find_all_by_id(Developer.jamises)
0
+  end
0
 end
...
43
44
45
 
 
46
47
48
...
43
44
45
46
47
48
49
50
0
@@ -43,6 +43,8 @@ class Developer < ActiveRecord::Base
0
 
0
   has_many :audit_logs
0
 
0
+  named_scope :jamises, :conditions => {:name => 'Jamis'}
0
+
0
   validates_inclusion_of :salary, :in => 50000..200000
0
   validates_length_of    :name, :within => 3..20
0
 

Comments