JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
JR not including type of polymorphic has_one when called to include it
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
The response from the server is missing the embedded target/data/type, or rather replacing it with the empty string...
class Api::V1::ActivityResource < JSONAPI::Resource
has_one :user
has_one :target, polymorphic: true
attributes :previous_value, :new_value, :message, :created_at
attribute :activity_type # this is included for now as JSONAPI::Resources sends model type as "activities"
def activity_type
@model.type
end
end
irb(main):001:0> Activity.first
Activity Load (0.7ms) SELECT "activities".* FROM "activities" ORDER BY "activities"."id" ASC LIMIT 1
=> #<NewRecord id: 1,
user_id: nil,
target_id: 239,
target_type: "Facility", # <= target_type is correct
previous_value: nil,
new_value: nil,
message: nil,
type: "NewRecord",
created_at: "2015-10-13 15:16:12",
updated_at: "2015-10-13 15:16:12">
http://localhost:3000/api/v1/activities/1?include=target,user:
{
"data": {
"id": "1",
"type": "activities",
"links": {
"self": "http://localhost:3000/api/v1/activities/1"
},
"attributes": {
"previous-value": null,
"new-value": null,
"message": null,
"created-at": "2015-10-13T15:16:12.964Z",
"type": "NewRecord"
},
"relationships": {
"user": {
"links": {
"self": "http://localhost:3000/api/v1/activities/1/relationships/user",
"related": "http://localhost:3000/api/v1/activities/1/user"
},
"data": null
},
"target": {
"links": {
"self": "http://localhost:3000/api/v1/activities/1/relationships/target",
"related": "http://localhost:3000/api/v1/activities/1/target"
},
"data": {
"type": "", // <== should be "Facility"
"id": "239"
}
}
}
}
}
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere die gezeigte ActivityResource-Anfrage mit include=target,user und untersuche, wie die polymorphe has_one :target-Beziehung ihren Ressourcenbezeichner erstellt. Verifiziere den Fix, indem du bestätigst, dass die Daten der eingeschlossenen Beziehung den Typ Facility und die ID 239 statt eines leeren Typs melden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rails, ruby
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100