DS.Store#pushPayload()

pushPayload (modelName, inputPayload)

Defined in addon/-private/system/store.js:2197

Push some raw data into the store.

This method can be used both to push in brand new records, as well as to update existing records. You can push in more than one type of object at once. All objects should be in the format expected by the serializer.

app/serializers/application.js
import DS from 'ember-data';

export default DS.ActiveModelSerializer;
var pushData = {
  posts: [
    { id: 1, post_title: "Great post", comment_ids: [2] }
  ],
  comments: [
    { id: 2, comment_body: "Insightful comment" }
  ]
}

store.pushPayload(pushData);

By default, the data will be deserialized using a default serializer (the application serializer if it exists).

Alternatively, pushPayload will accept a model type which will determine which serializer will process the payload.

app/serializers/application.js
import DS from 'ember-data';

export default DS.ActiveModelSerializer;
app/serializers/post.js
import DS from 'ember-data';

export default DS.JSONSerializer;
store.pushPayload('comment', pushData); // Will use the application serializer
store.pushPayload('post', pushData); // Will use the post serializer

Parameters:

modelName String
Optionally, a model type used to determine which serializer will be used
inputPayload Object
doc_EmberJs
2016-11-30 16:50:54
Comments
Leave a Comment

Please login to continue.