Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow store.push to accept { data: null } #3866

Merged
merged 1 commit into from Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/ember-data/lib/system/store.js
Expand Up @@ -1683,7 +1683,13 @@ Store = Service.extend({
return internalModels.map((internalModel) => internalModel.getRecord());
}

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 @@ -1694,7 +1700,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
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
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
});
});
});