findRecord (store, type, id, snapshot) Promise
The findRecord()
method is invoked when the store is asked for a record that has not previously been loaded. In response to findRecord()
being called, you should query your persistence layer for a record with the given ID. The findRecord
method should return a promise that will resolve to a JavaScript object that will be normalized by the serializer.
Here is an example findRecord
implementation:
app/adapters/application.js
import DS from 'ember-data'; export default DS.Adapter.extend({ findRecord: function(store, type, id, snapshot) { return new Ember.RSVP.Promise(function(resolve, reject) { Ember.$.getJSON(`/${type.modelName}/${id}`).then(function(data) { resolve(data); }, function(jqXHR) { reject(jqXHR); }); }); } });
Parameters:
-
store
DS.Store
-
type
DS.Model
-
id
String
-
snapshot
DS.Snapshot
Returns:
-
Promise
- promise
Please login to continue.