geared_pagination icon indicating copy to clipboard operation
geared_pagination copied to clipboard

Extending unscope?

Open danielpuglisi opened this issue 6 years ago • 1 comments

Hi there

I'm currently building an API with geared_pagination and was wondering if it would make sense to add unscope(:select, :order, :group) to GearedPagination::Recordset#records_count as it otherwise causes some trouble with more complex queries. I don't think select, order and group are required here. But maybe I'm missing something?

For example here is a query that I'm trying to resolve:

Event.joins(:event_parts)
  .where('event_parts.ends_at > ?', Time.zone.now)
  .order(Arel.sql('min(event_parts.starts_at)'))
  .group('events.id')
  .preload(:event_parts)

Which results in an TypeError: no implicit conversion of Integer into Hash exception because the count result is grouped by events.id.

danielpuglisi avatar Feb 22 '19 17:02 danielpuglisi

I realized this issue was here after I ran into it myself. This PR https://github.com/basecamp/geared_pagination/pull/49 fixes it

smridge avatar Dec 05 '22 23:12 smridge