paginator: fix page counts for relations with group by clauses.
Fix an invalid SQL exception that occurs when the paginator tries to do a COUNT(*) to calculate the page count of a relation that already includes a GROUP BY + COUNT(*) clause. We need to nest the whole query inside a `SELECT COUNT(*) FROM (...)` subquery so the inner COUNT(*) doesn't mess up the outer COUNT(*). Fixes #4285.
This commit is contained in:
@@ -104,7 +104,7 @@ module PaginationExtension
|
||||
|
||||
# taken from kaminari (https://github.com/amatsuda/kaminari)
|
||||
def total_count
|
||||
@paginator_count ||= except(:offset, :limit, :order).reorder(nil).count
|
||||
@paginator_count ||= unscoped.from(except(:offset, :limit, :order).reorder(nil)).count
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
if e.to_s =~ /statement timeout/
|
||||
1_000_000
|
||||
|
||||
Reference in New Issue
Block a user