JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Strategy for grouped resources

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

まだ誰も着手していません。

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

説明

I realize this isn't exclusively a JR question, but I feel it's too common to not bring it up and how one might accomplish it using JR.

My current use case has a type of model that's the basis for summed queries grouped by one or more attributes. In this case, it's a timesheet entry, and I initially need to group them by user_id and project_id, but they could easily be grouped by time periods as well. The aggregated value is SUM(hours). I've created an TimesheetEntryCollection model as an ActiveModel::Model object to handle the aggregated data, but I'm unsure how to serialize them, as JR expects and ActiveRecord::Relation to be returned from the Resource's self.records method and I'm not sure how to force a relation out of a tableless model. Do I just need to override the controller methods, or is there some way to do this through the resource?

Am I thinking about this the wrong way? Should JR maybe allow arrays to be returned from self.records with the understanding that you have to handle pagination/filtering yourself?

Any help would be greatly appreciated!

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

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

はじめの一歩

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

調査の方向性

まず Resource の self.records 契約とレポートで言及されている controller メソッドから始め、JR が ActiveRecord::Relation をどのようにシリアライズするかを追跡します。その経路を、テーブルを持たない ActiveModel::Model の TimesheetEntryCollection と、グループ化された SUM(hours) のユースケースと比較します。グループ化されたリソースに対する合意済みのアプローチが定まり、配列と呼び出し元が管理するページネーションまたはフィルタリングをサポートするかどうかも含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rails, ruby
領域
api, backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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