From c7f333db87bacc7f5b5a85c55738bf4dc740befc Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Tue, 15 May 2018 20:41:26 -0500 Subject: [PATCH] Remedy for SELECT COUNT(DISTINCT *) FROM ... 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. --- lib/tabulatr/data/data.rb | 2 +- lib/tabulatr/data/pagination.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tabulatr/data/data.rb b/lib/tabulatr/data/data.rb index dd41a35..1d8a511 100644 --- a/lib/tabulatr/data/data.rb +++ b/lib/tabulatr/data/data.rb @@ -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) diff --git a/lib/tabulatr/data/pagination.rb b/lib/tabulatr/data/pagination.rb index 963bd41..68e2eb9 100644 --- a/lib/tabulatr/data/pagination.rb +++ b/lib/tabulatr/data/pagination.rb @@ -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