Permalink
Browse files

Adding unsaved records to hasMany relationships after they are normal…

…ized from saved payload.
  • Loading branch information...
pzuraq
pzuraq committed Oct 5, 2013
1 parent 6bf433e commit 829753e4cb66d6ac93bac5b9983ed7056633d266
Showing with 9 additions and 0 deletions.
  1. +9 −0 packages/ember-data/lib/system/store.js
@@ -1372,6 +1372,7 @@ function normalizeRelationships(store, type, data, record) {
deserializeRecordId(store, data, key, relationship, value);
} else if (kind === 'hasMany') {
deserializeRecordIds(store, data, key, relationship, value);
addUnsavedRecords(record, key, value);
}
});
@@ -1408,6 +1409,14 @@ function deserializeRecordIds(store, data, key, relationship, ids) {
}
}
// If there are any unsaved records that are in a hasMany they won't be
// in the payload, so add them back in manually.
function addUnsavedRecords(record, key, data) {
if(record) {
data.pushObjects(record.get(key).filterBy('isNew'));
}
}
// Delegation to the adapter and promise management
DS.PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);

2 comments on commit 829753e

@andriybuday

This comment has been minimized.

Show comment
Hide comment
@andriybuday

andriybuday Jan 2, 2014

This code comes with assumption that "any unsaved records that are in a hasMany they won't be in the payload" which won't be true if serializer/backend response are custom and handle oneToMany relationship.

Should it mean that in such cases child items should be manually marked as not new?

andriybuday replied Jan 2, 2014

This code comes with assumption that "any unsaved records that are in a hasMany they won't be in the payload" which won't be true if serializer/backend response are custom and handle oneToMany relationship.

Should it mean that in such cases child items should be manually marked as not new?

@andriybuday

This comment has been minimized.

Show comment
Hide comment
@andriybuday

andriybuday Jul 8, 2015

Looks like it is fixed as of ember-data 1.0.0-beta9 by adding uniqById check in line 1416.
Removed some nasty override from our app.

andriybuday replied Jul 8, 2015

Looks like it is fixed as of ember-data 1.0.0-beta9 by adding uniqById check in line 1416.
Removed some nasty override from our app.

Please sign in to comment.