JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

has_one foreign_key_on: :related fails on save

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

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

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

説明

When saving a resource with a has_one relationship with foreign_key_on: :related I get an error of undefined method 'foreign_key=' for the model. I'm not sure if the intent is to change the relationship on the related items when save or not. For now I did the following patch to not update any relationships that have foreign_key_on: :related

def replace_to_one_link(relationship_type, relationship_key_value)
  if(self.class._relationships[relationship_type.to_sym]).belongs_to?
    super
  end
end

def replace_polymorphic_to_one_link(relationship_type, relationship_key_value, relationship_key_type)
  if(self.class._relationships[relationship_type.to_sym]).belongs_to?
    super
  end
end

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

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

はじめの一歩

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

調査の方向性

まず、foreign_key_on: :related を使用する has_one リレーションの保存失敗を再現し、次に replace_to_one_link と replace_polymorphic_to_one_link を通るリレーション保存パスを追跡します。related items のリレーションに対する意図された動作を判断し、失敗するケースのカバレッジを追加または更新します。保存時に利用できない foreign_key= メソッドが呼び出されなくなり、意図されたリレーションの動作が検証されれば完了です。

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

評価

技術スタック
rails, ruby
領域
api, backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
28/100

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

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