JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Related resources not backed by an association

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

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

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

説明

Hello, I'm curious to see if anyone is interested in allowing a resource to have a relationship that isn't necessarily an association to the underlying model. For example:

A Video has_many :tags. I've created an instance method (Video#related_videos) that pulls related videos based on a video's set of tags.

video.related_videos
=> [related_video_1, related_video_2]

What I'm interested in is having the corresponding VideoResource aware that this isn't an association it should be looking for, but rather public method. This would allow the following requests:

videos/:id?include=related_videos
videos/:id/relationships/related_videos

Currently, an InvalidInclude exception will be raised since "related_videos is not a valid relationship of videos." What if we were to pass a flag to relationship / has_many / has_one? Maybe there's a better way, but I was thinking something like:

VideoResource < JSONAPI::Resource
  has_many :related_videos, instance_method: true
end

Would something like this be worth exploring? I'd be happy to work on a PR to support something like this if there's any interest.

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

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

はじめの一歩

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

調査の方向性

まず、issue で説明されているリソース関係の宣言(relationshiphas_manyhas_one)と InvalidInclude パスを確認します。Video#related_videos のような public メソッドを 2 つのリクエスト例を通じてどのように表現し公開できるかを判断します。完了条件では、API とバリデーションの動作について合意する必要があります。

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

評価

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

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

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