ember-data-save-relationships icon indicating copy to clipboard operation
ember-data-save-relationships copied to clipboard

How to serialize a child of a child?

Open joshuataylor opened this issue 8 years ago • 3 comments

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 }
  }
});

joshuataylor avatar Jan 03 '17 15:01 joshuataylor

Hi @joshuataylor did you solved your issue ?

tomdrn avatar Jun 07 '17 10:06 tomdrn

@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.

joshuataylor avatar Jun 07 '17 11:06 joshuataylor

Did anyone ever figure this out?

RobbieTheWagner avatar Jul 07 '17 14:07 RobbieTheWagner