Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ActiveRecord::Relation#empty? when count is performed on a grouped query. #178

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/will_paginate/active_record.rb
Expand Up @@ -81,7 +81,12 @@ def size
# overloaded to be pagination-aware
def empty?
if !loaded? and offset_value
count <= offset_value
rel_count = count
if rel_count.respond_to?(:size) and !rel_count.is_a?(Integer)
rel_count.size <= offset_value
else
rel_count <= offset_value
end
else
super
end
Expand Down
7 changes: 7 additions & 0 deletions spec/finders/active_record_spec.rb
Expand Up @@ -131,6 +131,13 @@
topics.should_not be_empty
}.should run_queries(1)
end

it "support empty? for grouped queries" do
topics = Topic.group(:project_id).paginate :page => 1, :per_page => 3
lambda {
topics.should_not be_empty
}.should run_queries(1)
end

it "overrides total_entries count with a fixed value" do
lambda {
Expand Down