basecamp / basecamp/geared_pagination

Extending unscope?

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
913
Forks
24
Avg merge
21h 32m
Merged PRs (30d)
1

Description

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](https://github.com/basecamp/geared_pagination/blob/96d51c1490d9c4754a74f7eada92e5ed76ee71af/lib/geared_pagination/recordset.rb#L32) 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`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in lib/geared_pagination/recordset.rb at GearedPagination::Recordset#records_count and reproduce the Event.joins(:event_parts) query shown in the issue. Inspect how the grouped relation is counted and evaluate the proposed unscope of select, order, and group. Done means the example no longer raises TypeError and the count behavior remains correct for ordinary relations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.