JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Resource interacts with HasOne and HasMany differently

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

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

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

説明

I have a model (User) that I want to expose on an API to a certain class of users. Those users will always have a given permission and expiration, so I want to set those on the server, rather than expose uneditable fields to the client.

class UserResource < JSONAPI::Resource
  has_many :permissions
  has_one  :expiration, foreign_key_on: :related

  before_create :add_defaults

  def add_defaults
    self.permissions << Permission.find_by(title: 'Admin')
    self.model.expiration = Expiration.new(date: Date.new(2015,12,30))
  end

I think it's odd that I need to call the underlying model in order to interact with has_one objects, and I suspect this is the case for created objects, but I haven't gotten that far yet. Ideally, I could call self.expiration= and I would get behavior similar to self.permissions<<.

Am I just using JSONAPI::Resource incorrectly, or is this something worth pursuing?

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

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

はじめの一歩

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

調査の方向性

UserResourceのリレーション宣言とそのbefore_createコールバックから始め、has_many permissionsのインタラクションとhas_one expirationのインタラクションを比較します。リソースレベルで期待される割り当ておよび作成の動作を特定し、焦点を絞ったテストで、has_oneの処理が要求されたhas_manyと同様の動作に一致することを確認します。

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

評価

技術スタック
rails, ruby
領域
api, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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