JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

ActiveRecord `count` with a Relation#group returns a hash, not an integer, which break Pagination

オープン
#984 コメント 4 件 リアクション 4 件 担当者 1 名 GitHub で見る

@lgebhardt がすでに取り組んでいます。

2020年7月10日 から。

Status: Needs Failing Test Type: Bug
主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。