You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deserializing a Resource Object/Relationship on create throws an error when no ID is provided #21
I'm trying to create a new resource with an existing template relationship and an address relationship that should become a new resource. Example POST request:
changed the title [-]Deserializing a Resource Object/Relationship on create throws an error when no ID is provdi[/-][+]Deserializing a Resource Object/Relationship on create throws an error when no ID is provided[/+]on Feb 12, 2018
So you'll want to work around that somehow by going off-spec. That doesn't help with this lib but it makes it less likely to get "fixed" here.
Regarding terminology and the creation optional ID thing, the error message is talking about "resource identifier objects", so let's see what those are.
You've got attributes for a new record in the relationship data. What goes in there?
Looking at the spec for relationships, then click on "resource identifier objects" you're back at the original statement of id and type being required.
So while perfectly sensible to want to create them together, it looks like you'll need to create one then the other, 2 requests, or modify your api endpoint to take attributes for the other models and create them on the side, so putting them in the "post" payload instead of in the related address model without an id.
Activity
[-]Deserializing a Resource Object/Relationship on create throws an error when no ID is provdi[/-][+]Deserializing a Resource Object/Relationship on create throws an error when no ID is provided[/+]heberuriegas commentedon Jul 8, 2018
Any workaround on this?
nruth commentedon Aug 9, 2018
I think this would need handling in jsonapi-parser
e.g.
That said, I don't think you can create the related object like that in json-api.
Batching / multiple creations at once seems to be work-in-progress for the spec:
json-api/json-api#1254 json-api/json-api#1197
So you'll want to work around that somehow by going off-spec. That doesn't help with this lib but it makes it less likely to get "fixed" here.
Regarding terminology and the creation optional ID thing, the error message is talking about "resource identifier objects", so let's see what those are.
http://jsonapi.org/format/#document-resource-identifier-objects says it needs id and type and doesn't have any get-outs for creation.
So what does permit creation without an ID?
http://jsonapi.org/format/#document-resource-objects talks about the client being able to request the server create the resource and fill in the id.
You've got attributes for a new record in the relationship data. What goes in there?
Looking at the spec for relationships, then click on "resource identifier objects" you're back at the original statement of id and type being required.
So while perfectly sensible to want to create them together, it looks like you'll need to create one then the other, 2 requests, or modify your api endpoint to take attributes for the other models and create them on the side, so putting them in the "post" payload instead of in the related address model without an id.