Permalink
Browse files

Only update array contents if it is not dirty

  • Loading branch information...
1 parent c1e6b49 commit 54fc0f5d90687289b1496dcec137395ef3a9925a Tom Dale committed with tomhuda May 24, 2012
View
4 packages/ember-data/lib/system/model/model.js
@@ -293,14 +293,14 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (association.kind === 'hasMany') {
cachedValue = this.cacheFor(name);
- if (cachedValue) {
+ if (cachedValue && !get(cachedValue, 'isDirty')) {
var key = association.options.key || name,
ids = data.get(key) || [];
var clientIds = Ember.ArrayUtils.map(ids, function(id) {
return store.clientIdForId(association.type, id);
});
- set(cachedValue, 'content', Ember.A(clientIds));
+ cachedValue.stateManager.send('update', Ember.A(clientIds));
cachedValue.fetch();
}
}
View
3 packages/ember-data/tests/integration/associations_test.js
@@ -129,7 +129,6 @@ test("it is possible to add an item to an association, remove it, then add it ag
if (count === 1) {
strictEqual(type, Person, "should first try to save the parent");
record.set('id', 1);
- debugger;
store.didCreateRecord(record);
} else if (count === 2) {
strictEqual(record, tag1, "should then save first tag");
@@ -157,6 +156,6 @@ test("it is possible to add an item to an association, remove it, then add it ag
store.commit();
- equal(getPath(person, 'tags.length'), 2, "object is removed from the association");
+ equal(getPath(person, 'tags.length'), 2, "association is correctly populated");
});

0 comments on commit 54fc0f5

Please sign in to comment.