Created
January 2, 2014 17:33
-
-
Save andriybuday/8222853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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