Saving inline child models while saving the parent model

We have a model with several child models:

// models/parent.js
export default DS.Model.extend({
    children: DS.hasMany("child")
});

// models/child.js
export default DS.Model.extend({
    parent: DS.belongsTo("parent")
});

      

The serializer of the parent model is configured using the EmbeddedRecordsMixin

following:

// serializers/parent.js
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        children: { embedded: "always" }
    }
});

      

If we call it an save

instance of the parent model, will the children be marked as saved? Or do we need to call save on each child model from the parent model adapter?

Also, if we define a serializer for child models, will it be used to serialize the children during the parent serialization process? Or will ED use the default serializer?

+3


source to share


1 answer


when I needed to store nested models, I overridden the serializeBelongsTo and serializeHasMany serialization methods to get all the information in json and then parsed it server side.



0


source







All Articles