public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Remove :include option from count_all query when it's possible.
denis (author)
Thu May 15 11:11:22 -0700 2008
mislav (committer)
Fri May 30 04:27:41 -0700 2008
commit  1f990837bcabf1c89e93e3b0d5d9e2b0bb67a79b
tree    c452dc98f54398e39fcb2314306c22413ce73c30
parent  177b217bdc3caa0cfe2d4e41be15e1a45417ea4b
...
158
159
160
161
 
 
 
 
 
 
 
 
162
163
164
...
158
159
160
 
161
162
163
164
165
166
167
168
169
170
171
0
@@ -158,7 +158,14 @@ module WillPaginate::Finders
0
       # merge the hash found in :count
0
       # this allows you to specify :select, :order, or anything else just for the count query
0
       count_options.update options[:count] if options[:count]
0
-
0
+
0
+ # forget about includes if they are irrelevant (Rails 2.1)
0
+ if count_options[:include] and
0
+ klass.private_methods.include?('references_eager_loaded_tables?') and
0
+ !klass.send(:references_eager_loaded_tables?, count_options)
0
+ count_options.delete :include
0
+ end
0
+
0
       count_options
0
     end
0
   end
...
225
226
227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
229
230
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
0
@@ -225,6 +225,24 @@ describe WillPaginate::Finders::ActiveRecord do
0
       result.should == expected
0
       result.total_entries.should == 4
0
     end
0
+
0
+ # detect ActiveRecord 2.1
0
+ if ActiveRecord::Base.private_methods.include?('references_eager_loaded_tables?')
0
+ it "should remove :include for count" do
0
+ Developer.expects(:find).returns([1])
0
+ Developer.expects(:count).with({}).returns(0)
0
+
0
+ Developer.paginate :page => 1, :per_page => 1, :include => :projects
0
+ end
0
+
0
+ it "should keep :include for count when they are referenced in :conditions" do
0
+ Developer.expects(:find).returns([1])
0
+ Developer.expects(:count).with({ :include => :projects, :conditions => 'projects.id > 2' }).returns(0)
0
+
0
+ Developer.paginate :page => 1, :per_page => 1,
0
+ :include => :projects, :conditions => 'projects.id > 2'
0
+ end
0
+ end
0
   end
0
   
0
   protected

Comments

    No one has commented yet.