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
lifo (committer)
Thu Aug 21 08:11:28 -0700 2008
commit  49c0e1e594c95d7e8446ebabecc9147afa62de7d
tree    fc260ee34139101764af8005d4284e3b4b913652
parent  a970f916fb1e05376733e2d42d9bcc2b873af355
...
1750
1751
1752
1753
 
1754
1755
1756
...
1750
1751
1752
 
1753
1754
1755
1756
0
@@ -1750,7 +1750,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
...
242
243
244
 
 
 
 
245
...
4
5
6
7
8
9
10
...
243
244
245
246
247
248
249
250
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
@@ -242,4 +243,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