JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Included resource choosing wrong Arel table

Offen
#1,127 6 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Ruby
Sterne
2.3k
Forks
546
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in JSONAPI::Resource#preload_include_fragments und untersuche, wie pluck_attrs seine Arel::Table während des beschriebenen JobApplication/User-Includes auswählt. Reproduziere das Problem mit der im Bericht angegebenen Association-Konfiguration und verifiziere anschließend, dass das Einbeziehen von user user_id 68 statt Account ID 11 verwendet und nicht mehr den Fehler auslöst, dass der Schlüssel nicht gefunden wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rails, ruby
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.