updateRecord (store, type, snapshot) Promise
Implement this method in a subclass to handle the updating of a record.
Serializes the record update and sends it to the server.
The updateRecord method is expected to return a promise that will resolve with the serialized record. This allows the backend to inform the Ember Data store the current state of this record after the update. If it is not possible to return a serialized record the updateRecord promise can also resolve with undefined
and the Ember Data store will assume all of the updates were successfully applied on the backend.
Example
app/adapters/application.js
import DS from 'ember-data'; export default DS.Adapter.extend({ updateRecord: function(store, type, snapshot) { var data = this.serialize(snapshot, { includeId: true }); var id = snapshot.id; return new Ember.RSVP.Promise(function(resolve, reject) { Ember.$.ajax({ type: 'PUT', url: `/${type.modelName}/${id}`, dataType: 'json', data: data }).then(function(data) { Ember.run(null, resolve, data); }, function(jqXHR) { jqXHR.then = null; // tame jQuery's ill mannered promises Ember.run(null, reject, jqXHR); }); }); } });
Parameters:
-
store
DS.Store
-
type
DS.Model
- the DS.Model class of the record
-
snapshot
DS.Snapshot
Returns:
-
Promise
- promise
Please login to continue.