Documentation / @ember-data/legacy-compat / index / pushPayload
ts
function pushPayload(
this,
modelName,
inputPayload): void;
Defined in: index.ts:252
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.
js
import RESTSerializer from '@ember-data/serializer/rest';
export default class ApplicationSerializer extends RESTSerializer;
js
let pushData = {
posts: [
{ id: 1, postTitle: "Great post", commentIds: [2] }
],
comments: [
{ id: 2, commentBody: "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.
js
import RESTSerializer from '@ember-data/serializer/rest';
export default class ApplicationSerializer extends RESTSerializer;
js
import JSONSerializer from '@ember-data/serializer/json';
export default JSONSerializer;
js
store.pushPayload(pushData); // Will use the application serializer
store.pushPayload('post', pushData); // Will use the post serializer
Parameters
this
modelName
string
Optionally, a model type used to determine which serializer will be used
inputPayload
Returns
void