-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create record with new hasMany relationship sends empty ids instead of attributes #3953
Comments
This looks like a bug to me. We wouldn't want to serialize new records before they have been saved. Not 100% sure what the correct path here would be.
Hm, I don't think "embedded" records in relationships are a thing in JSON API at all? Unsure though. Can you point me to the part of the spec that made you think this is the recommended behavior? |
@wecc I think you are right. The JSONAPI spec does not explicitly support what I'm trying to do. It seems natural though, and need it to atomically create a new record with relationships. I'll go on the jsonapi discuss to see if they are looking at extending the spec for these kinds of requests. Thanks! |
@wecc Ember-Data already supports serializing relationships through the EmbeddedRecordsMixin. Thanks to @lolmaus at json-api/json-api#795 (comment) Adding the EmbeddedRecordsMixin was as easy as creating a custom serializer for import DS from 'ember-data'
import ApplicationSerializer from 'face/application/serializer'
export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
author: { embedded: 'always' }
}
}) |
With this Book model:
When creating a record with new authors.
The author relationships are serialised as if they were already persisted. The relationship is serialised as a Resource Identifier Object.
From my understanding of JSONAPI, the unpersisted relationship should be serialised as a Resource Object with attributes.
The text was updated successfully, but these errors were encountered: