danr1979
danr1979

Reputation: 461

Saving models and their relationships using the new Ember Data JSONAPISerializer/Adapter

I have implemented a JSON-API backend and I'm using ember (1.13.4) and ember data (1.13.5) to pull my data in to the store using the new JSONAPIAdapter / JSONAPISerializer. All is working well and the store is populated with all of the models and their attributes/relationships.

However, when I call the .save() method on my models the JSON-API-formatted request that is generated doesn't contain the "included" key with all related models inside it. This means that if I modify an attribute in a related model and then save the primary model I don't see the changed attribute from the related model in the JSON payload.

What is the correct way to save models and their relationships so they are embedded using the new JSONAPIAdapter / JSONAPISerializer? I tried the EmbeddedRecordsMixin but this resulted in null attribute values within the "attributes" key of the payload.

If anyone can assist me with this I'd be grateful.

Thanks.

Upvotes: 3

Views: 561

Answers (1)

danr1979
danr1979

Reputation: 461

Ok, this has been answered on the Ember forum as follows:

"The standard does not support this at the moment and is scheduled for v1.1 (http://discuss.jsonapi.org/t/json-api-weekly-meeting-june-22nd-2015/23).

Your best bet would be to inherit from the serializer and implement your own standard for now. Just remember to include the included paths in your URL so that your server can reply with all the updated entities."

More information can be found here.

Upvotes: 1

Related Questions