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
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||
|
||||
<% if (@current_item.try(:prev_page) rescue false) %>
|
||||
<% if @current_item.try(:prev_page) %>
|
||||
<%= tag.link rel: "prev", href: url_for(nav_params_for(@current_item.prev_page)) %>
|
||||
<% end %>
|
||||
|
||||
<% if (@current_item.try(:next_page) rescue false) %>
|
||||
<% if @current_item.try(:next_page) %>
|
||||
<%= tag.link rel: "next", href: url_for(nav_params_for(@current_item.next_page)) %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user