JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Support foreign_type in has_one association

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

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

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

説明

I am updating an app to use jsonapi:resources and have had to change a model association name without changing the underlying table. This model had a polymorphic field :resource which is now called :item, however the underlying table still has fields resource_id and resource_type.

In my model I can do this:

belongs_to :item, polymorphic: true, foreign_key: "resource_id", foreign_type: "resource_type"

However when I do this in my resource file:

has_one :item, polymorphic: true, foreign_key: 'resource_id', foreign_type: 'resource_type'

I receive an error "undefined method item_type=". From the docs it looks like foreign_key is supported but foreign_type is not. Could this be easily fixed?

Thanks for a great gem, it's been a pleasure to work with!

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

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

はじめの一歩

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

調査の方向性

has_one アソシエーションの処理と既存の foreign_key サポートから始め、次に issue に示されているモデルとリソースの設定を再現します。foreign_type が未定義の item_type= メソッドを呼び出さずに受け入れられ、モデル名が基になる型カラムと異なるポリモーフィックなアソシエーションをカバーするテストがあれば完了です。

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

評価

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

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

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