Permalink
Browse files

Exclude reorder for count queries.

It turns out reorder behaves differently on Rails 3.1 and requires
explicit exclude to not pollute count query with order clause.
  • Loading branch information...
1 parent 4289490 commit bd00b43d385b6456999524e8c92e7ce601d4d84f @pawelpacana pawelpacana committed with May 15, 2013
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/will_paginate/active_record.rb
  2. +5 −0 spec/finders/active_record_spec.rb
@@ -80,7 +80,7 @@ def total_entries
def count
if limit_value
- excluded = [:order, :limit, :offset]
+ excluded = [:order, :limit, :offset, :reorder]
excluded << :includes unless eager_loading?
rel = self.except(*excluded)
# TODO: hack. decide whether to keep
@@ -200,6 +200,11 @@
Developer.group(:salary).page(1).total_entries.should == 4
end
+ it "removes :reorder for count with group" do
+ Project.group(:id).reorder(:id).page(1).total_entries
+ $query_sql.last.should_not =~ /\ORDER\b/
+ end
+
it "should not have zero total_pages when the result set is empty" do
Developer.where("1 = 2").page(1).total_pages.should == 1
end

0 comments on commit bd00b43

Please sign in to comment.