Skip to content

Commit

Permalink
Remedy for SELECT COUNT(DISTINCT *) FROM ...
Browse files Browse the repository at this point in the history
For whatever reason using #joins and #select wreaks havoc
when calling #count without :all.
You'll likely need rails_select_on_includes gem
if you include extras in your #select list.
  • Loading branch information
mlt committed Jun 8, 2020
1 parent db75f18 commit c7f333d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tabulatr/data/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def data_for_table(params, locals: {}, default_order: nil, controller: nil, &blo
@default_order = default_order

# count
total = @relation.count
total = @relation.count(:all)

# prepare the query
apply_filters(filter_params params)
Expand Down
2 changes: 1 addition & 1 deletion lib/tabulatr/data/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def apply_pagination(offset: 0, pagesize: nil)
end

def compute_pagination(page, pagesize)
count = @relation.count
count = @relation.count(:all)
count = count.count if count.is_a?(Hash)
page ||= 1
pagesize, page = pagesize.to_i, page.to_i
Expand Down

0 comments on commit c7f333d

Please sign in to comment.