ActiveRecord `count` with a Relation#group returns a hash, not an integer, which break Pagination
@lgebhardt ci sta già lavorando.
Dal 10/7/2020.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
I came across this bug in a large Rails API my team is building. The issue is that ActiveRecord count method does not always return an integer. As explained in the docs:
If count is used with Relation#group, it returns a Hash whose keys represent the aggregated column, and the values are the respective amounts:
Person.group(:city).count # => { 'Rome' => 5, 'Paris' => 3 }
This breaks the expectation made in the various Paginator classes that record_count will be an integer.
The simple way to fix this is to handle the Hash case with hash.values.sum. I am putting in this Issue, instead of a MR, because I am not certain where in the stack you would think this should live. It could live in the AR adapter for find_count, it could live in the Processor when page_options[:record_count] is created, or it could live in the Paginator class.
If you give me any guidance on how you would like to fix this bug, I will happily put in the appropriate MR.
stephen
- Lingua principale
- Ruby
- Stelle
- 2.3k
- Fork
- 546
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JSONAPI-Resources/jsonapi-resources
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
ArgumentError with Rails 8.1 Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 commenti · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Tutte le issue di JSONAPI-Resources/jsonapi-resources
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
バグ
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Version bump for OpenVox 9 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
voxpupuli/puppet-epel#186 · 1 commento ·