Skip to content

Commit

Permalink
Merge pull request #3866 from bmac/issue-3790
Browse files Browse the repository at this point in the history
Allow store.push to accept { data: null }
  • Loading branch information
igorT committed Oct 29, 2015
2 parents 4bdfabc + 2f17c2d commit 31bf071
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,13 @@ Store = Service.extend({
return internalModels;
}

var internalModel = this._pushInternalModel(data.data || data);
if (data.data === null) {
return null;
}

Ember.assert(`Expected an object in the 'data' property in a call to 'push' for ${data.type}, but was ${Ember.typeOf(data.data)}`, Ember.typeOf(data.data) === 'object');

var internalModel = this._pushInternalModel(data.data);

return internalModel.getRecord();
},
Expand All @@ -1700,7 +1706,6 @@ Store = Service.extend({

_pushInternalModel: function(data) {
var modelName = data.type;
Ember.assert(`Expected an object as 'data' in a call to 'push' for ${modelName}, but was ${Ember.typeOf(data)}`, Ember.typeOf(data) === 'object');
Ember.assert(`You must include an 'id' for ${modelName} in an object passed to 'push'`, data.id != null && data.id !== '');
Ember.assert(`You tried to push data with a type '${modelName}' but no model could be found with that name.`, this._hasModelFor(modelName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ test("serializeHasMany omits unknown relationships on pushed record", function()

run(function() {
post = env.store.push({
id: "1",
type: "post",
attributes: {
title: "Rails is omakase"
data: {
id: "1",
type: "post",
attributes: {
title: "Rails is omakase"
}
}
});
});
Expand Down
11 changes: 11 additions & 0 deletions packages/ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,14 @@ test("Using store#deleteRecord should mark the model for removal", function() {
equal(personDeleteRecord.called.length, 1, 'expected person.deleteRecord to have been called');
ok(person.get('isDeleted'), 'expect person to be isDeleted');
});


test("Store should accept a null value for `data`", function() {
expect(0);

run(function() {
store.push({
data: null
});
});
});

0 comments on commit 31bf071

Please sign in to comment.