DS.Adapter#findRecord()

findRecord (store, type, id, snapshot) Promise

Defined in addon/adapter.js:88

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
doc_EmberJs
2016-11-30 16:49:23
Comments
Leave a Comment

Please login to continue.