Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andriybuday/8222853 to your computer and use it in GitHub Desktop.
Save andriybuday/8222853 to your computer and use it in GitHub Desktop.
didSaveRecord: function (record, data) {
if (data) {
this.didSaveRecordForHasManyItems(this, record.constructor, data, record);
}
this._super(record, data);
},
// Fixes introdution in ember-data.1.0.0.beta4 (see method "addUnsavedRecords" in Store)
// assume that "any unsaved records that are
// in a hasMany they won't be in the payload"
// which could be not true if serializer handles child items
didSaveRecordForHasManyItems: function (store, type, data, record) {
var self = this;
type.eachRelationship(function (key, relationship) {
var kind = relationship.kind,
value = data[key];
if (value === null) { return; }
if (kind === 'hasMany') {
record.get(key).forEach(function (childRecord) {
childRecord.adapterWillCommit();
childRecord.adapterDidCommit();
self.didSaveRecordForHasManyItems(store, childRecord.constructor, {}, childRecord);
});
}
});
return data;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment