diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index c84b2b8b346..3f03f423eb6 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1689,7 +1689,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(); }, @@ -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)); diff --git a/packages/ember-data/tests/integration/serializers/json-serializer-test.js b/packages/ember-data/tests/integration/serializers/json-serializer-test.js index d1a673a8b4b..7256902661c 100644 --- a/packages/ember-data/tests/integration/serializers/json-serializer-test.js +++ b/packages/ember-data/tests/integration/serializers/json-serializer-test.js @@ -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" + } } }); }); diff --git a/packages/ember-data/tests/integration/store-test.js b/packages/ember-data/tests/integration/store-test.js index 023ecd73f34..cafb160efe7 100644 --- a/packages/ember-data/tests/integration/store-test.js +++ b/packages/ember-data/tests/integration/store-test.js @@ -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 + }); + }); +});