public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Fixed that using :include together with :conditions array in Base.find 
would cause NoMethodError #2887 [Paul Hammmond]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3241 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Wed Dec 07 20:46:40 -0800 2005
commit  c6120acc006ec7b6a2bc9353fb384169cb162388
tree    1d6e3ade56e3ee05d0c4745aecc375932d07115e
parent  60d68aab53e261854fea30a3a85da92191395950
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * SVN*
0
 
0
+* Fixed that using :include together with :conditions array in Base.find would cause NoMethodError #2887 [Paul Hammmond]
0
+
0
 * PostgreSQL: more robust sequence name discovery. #3087 [Rick Olson]
0
 
0
 * Oracle: use syntax compatible with Oracle 8. #3131 [Michael Schoen]
...
980
981
982
983
984
985
 
 
 
 
986
987
988
...
980
981
982
 
 
 
983
984
985
986
987
988
989
0
@@ -980,9 +980,10 @@
0
         end
0
 
0
         def include_eager_conditions?(options)
0
- return false unless options[:conditions]
0
-
0
- options[:conditions].scan(/ ([^.]+)\.[^.]+ /).flatten.any? do |condition_table_name|
0
+ conditions = options[:conditions]
0
+ return false unless conditions
0
+ conditions = conditions.first if conditions.is_a?(Array)
0
+ conditions.scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name|
0
             condition_table_name != table_name
0
           end
0
         end
...
83
84
85
 
 
 
 
 
 
86
87
88
...
99
100
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
103
104
...
83
84
85
86
87
88
89
90
91
92
93
94
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
0
@@ -83,6 +83,12 @@
0
     assert_equal [6,7,8], comments.collect { |c| c.id }
0
   end
0
   
0
+ def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array
0
+ comments = Comment.find(:all, :include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id')
0
+ assert_equal 3, comments.length
0
+ assert_equal [6,7,8], comments.collect { |c| c.id }
0
+ end
0
+
0
   def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations
0
     posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1)
0
     assert_equal 1, posts.length
0
@@ -99,6 +105,24 @@
0
     posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
0
     assert_equal 2, posts.size
0
     assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
0
+ end
0
+
0
+ def test_eager_with_has_many_and_limit_and_conditions
0
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id")
0
+ assert_equal 2, posts.size
0
+ assert_equal [4,5], posts.collect { |p| p.id }
0
+ end
0
+
0
+ def test_eager_with_has_many_and_limit_and_conditions_array
0
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id")
0
+ assert_equal 2, posts.size
0
+ assert_equal [4,5], posts.collect { |p| p.id }
0
+ end
0
+
0
+ def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
0
+ assert_raises(ArgumentError) do
0
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ])
0
+ end
0
   end
0
 
0
   def test_eager_with_has_many_and_limit_with_no_results

Comments

    No one has commented yet.