frank06 / ember-data-save-relationships

A mixin for Ember Data JSON API serializers to save relationship data
https://github.com/laborvoices/ember-data-save-relationships
MIT License
41 stars 20 forks source link

How to serialize a child of a child? #19

Open joshuataylor opened 7 years ago

joshuataylor commented 7 years ago

Let's say I have the following models setup:

A -> B -> C -> D

This all needs to be saved at the same time, and can be validated on the server, so if A/B/C/D is invalid, the transaction won't save.

I can save A & B, using the following for a.js:

import JSONAPISerializer from 'ember-data/serializers/json-api';
import SaveRelationshipsMixin from 'ember-data-save-relationships';

export default JSONAPISerializer.extend(SaveRelationshipsMixin, {
  attrs: {
    b: { serialize: true }
  }
});

This now sends A & B to the server.

But how do I also send C & D?

In b.js, I should be able to do:

import JSONAPISerializer from 'ember-data/serializers/json-api';
import SaveRelationshipsMixin from 'ember-data-save-relationships';

export default JSONAPISerializer.extend(SaveRelationshipsMixin, {
  attrs: {
    c: { serialize: true }
  }
});
tomdrn commented 7 years ago

Hi @joshuataylor did you solved your issue ?

joshuataylor commented 7 years ago

@thomasdurin Nope, ended up using a status field for the parent, then deleting if it didn't. My data could handle that, but can think of so many instances it wouldn't.

RobbieTheWagner commented 7 years ago

Did anyone ever figure this out?