JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Included resource choosing wrong Arel table

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

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

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

説明

I'm running into an issue where including one resource (user) ends up using another Arel table (account), and thus the include blows up with Internal Server Error: key not found: 11. 11 is the Account ID of the user, but the user ID is 68, which is specified on the parent resource as user_id.

I've stepped through the code a bit to determine that pluck_attrs in JSONAPI::Resource#preload_include_fragments has the wrong Arel::Table but I'm not sure what the cause of that is.

My models and resources are configured in a very straightforward manner:

JobApplication < ApplicationRecord
  belongs_to :user, inverse_of: :job_applications, touch: true, counter_cache: true
end

User < ApplicationRecord
  has_many :job_applications, inverse_of: :user, dependent: :destroy
end

Any idea why this would be happening?

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

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

はじめの一歩

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

調査の方向性

JSONAPI::Resource#preload_include_fragments から始め、説明されている JobApplication/User の include 中に pluck_attrs がどのように Arel::Table を選択するかを調べます。レポートに記載された関連付け設定で問題を再現し、user を include すると Account ID 11 ではなく user_id 68 が使われ、キーが見つからないエラーが発生しなくなることを確認します。

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

評価

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

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

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