Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Aug 27, 2013
1 parent d96327c commit 01ad4a9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
2 changes: 2 additions & 0 deletions packages/ember-data/lib/system/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ DS.Adapter = Ember.Object.extend(DS._Mappable, {
adapter = this;

return resolve(promise).then(function(payload) {
Ember.assert("You made a request for a " + type.typeKey + " with id " + id + ", but the adapter's response did not have any data", payload);
payload = adapter.extract(store, type, payload, id, 'find');

return store.push(type, payload);
});
},
Expand Down
3 changes: 2 additions & 1 deletion packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (relationship.kind === 'belongsTo') {
set(this, name, null);
} else if (relationship.kind === 'hasMany') {
this.clearHasMany(relationship);
var hasMany = this._relationships[relationship.name];
if (hasMany) { hasMany.clear(); }
}
}, this);
},
Expand Down
34 changes: 0 additions & 34 deletions packages/ember-data/lib/system/relationships/has_many.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,3 @@ DS.hasMany = function(type, options) {
Ember.assert("The type passed to DS.hasMany must be defined", !!type);
return hasRelationship(type, options);
};

function clearUnmaterializedHasMany(record, relationship) {
var data = get(record, 'data');

var references = data[relationship.key];

if (!references) { return; }

var inverse = record.constructor.inverseFor(relationship.key);

if (inverse) {
forEach(references, function(reference) {
var childRecord;

if (childRecord = reference.record) {
record.suspendRelationshipObservers(function() {
set(childRecord, inverse.name, null);
});
}
});
}
}

DS.Model.reopen({
clearHasMany: function(relationship) {
var hasMany = this.cacheFor(relationship.name);

if (hasMany) {
hasMany.clear();
} else {
clearUnmaterializedHasMany(this, relationship);
}
}
});
2 changes: 2 additions & 0 deletions packages/ember-data/tests/unit/store/adapter_interop_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test("Calling Store#find invokes its adapter#find", function() {
equal(store, currentStore, "Adapter#find was called with the right store");
equal(type, currentType, "Adapter#find was called with the type passed into Store#find");
equal(id, 1, "Adapter#find was called with the id passed into Store#find");

return Ember.RSVP.resolve({ id: 1 });
}
});

Expand Down

0 comments on commit 01ad4a9

Please sign in to comment.