JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
JR not including type of polymorphic has_one when called to include it
Nessuno ha ancora preso questa issue.
- Lingua principale
- Ruby
- Stelle
- 2.3k
- Fork
- 546
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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"
}
}
}
}
}
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci la richiesta ActivityResource mostrata con include=target,user e verifica come la relazione polimorfica has_one :target costruisce il proprio identificatore di risorsa. Verifica la correzione confermando che i dati della relazione inclusa riportano il tipo Facility e l’id 239 invece di un tipo vuoto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rails, ruby
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100