I’m running into an issue with the REST Adapter/Serializer and EmbeddedRecordsMixin, specifically my app needs to be able to sideload an model’s parent record in create/POST responses, and that parent model contains the child record embedded in a hasMany array. This is resulting in “You cannot update the id index of an InternalModel once set.” errors. heres a simplified version of the JSON structure my api is returning:
// for POST /child-model
{
"childModel": {
"id": 1,
"foo": "Bar"
},
"parentModel": {
"id": 2,
"children": [
{
"id": 1,
"foo": "Bar"
}
]
}
}
//child-model
DS.Model.extend({
foo: attr('string')
});
//parent-model
DS.Model.extend({
children: hasMany('child-model')
});
so it seems like ember data doesnt like that I’m returning what it sees as a duplicate of the newly created childModel record, when it really should just see it as an “update” to that new childModel, and be only connecting it to the parentModel via the hasMany relationship. It appears this is because ember-data is processing the sideloaded parentModel data first, so its pushing in the ID #1 childModel into the store as an existing model, and therefore by the time it gets to the top level childModel data, the ID #1 model is already in the store.
This is running ember-data 2.14.10 (and tried 2.15-beta.4 as well) I feel like ember-data should be smart enough to handle this, or is there something I’m missing?