Class DS.FixtureAdapter

DS.FixtureAdapter is an adapter that loads records from memory. It's primarily used for development and testing. You can also use DS.FixtureAdapter while working on the API but is not ready to integrate yet. It is a fully functioning adapter. All CRUD methods are implemented. You can also implement query logic that a remote system would do. It's possible to develop your entire application with DS.FixtureAdapter.

For information on how to use the FixtureAdapter in your application please see the FixtureAdapter guide.

Show:

Module: ember-data
payload
Object
returns
Object

an object formatted the way DS.Store understands

This method converts a JSON-API Resource Object to a format that DS.Store understands.

TODO: This method works as an interim until DS.Store understands JSON-API.

Module: ember-data
store
DS.Store
typeClass
DS.Model
snapshot
DS.Snapshot
returns
Promise

promise

Module: ember-data
store
DS.Store
typeClass
DS.Model
snapshot
DS.Snapshot
returns
Promise

promise

Module: ember-data
store
DS.Store
typeClass
DS.Model
id
String
snapshot
DS.Snapshot
returns
Promise

promise

Module: ember-data
store
DS.Store
type
DS.Model
sinceToken
String
snapshotRecordArray
DS.SnapshotRecordArray
returns
Promise

promise

The findAll() method is used to retrieve all records for a given type.

Example

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

export default DS.Adapter.extend({
  findAll: function(store, type, sinceToken) {
    var url = type;
    var query = { since: sinceToken };
    return new Ember.RSVP.Promise(function(resolve, reject) {
      jQuery.getJSON(url, query).then(function(data) {
        Ember.run(null, resolve, data);
      }, function(jqXHR) {
        jqXHR.then = null; // tame jQuery's ill mannered promises
        Ember.run(null, reject, jqXHR);
      });
    });
  }
});
Module: ember-data
store
DS.Store
typeClass
DS.Model
ids
Array
snapshots
Array
returns
Promise

promise

Module: ember-data
store
DS.Store
type
DS.Model
id
String
snapshot
DS.Snapshot
returns
Promise

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. Once found, you can asynchronously call the store's push() method to push the record into the store.

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) {
    var url = [type.modelName, id].join('/');

    return new Ember.RSVP.Promise(function(resolve, reject) {
      jQuery.getJSON(url).then(function(data) {
        Ember.run(null, resolve, data);
      }, function(jqXHR) {
        jqXHR.then = null; // tame jQuery's ill mannered promises
        Ember.run(null, reject, jqXHR);
      });
    });
  }
});
Module: ember-data
typeClass
DS.Model
returns
Array

Implement this method in order to provide data associated with a type

Module: ember-data
store
DS.Store
returns
String

id

Module: ember-data
store
DS.Store
snapshots
Array
returns
Array

an array of arrays of records, each of which is to be loaded separately by findMany.

Organize records into groups, each of which is to be passed to separate calls to findMany.

For example, if your api has nested URLs that depend on the parent, you will want to group records by their parent.

The default implementation returns the records as a single group.

Module: ember-data
store
DS.Store
typeClass
DS.Model
snapshot
DS.Snapshot

Implement this method in order to provide json for CRUD methods

Module: ember-data
serializer
DS.Serializer
store
DS.Store
modelClass
subclass of DS.Model
payload
Object
id
String|Number
requestType
String
returns
Object

JSON-API Document

This is a helper method that always returns a JSON-API Document.

If the current serializer has isNewSerializerAPI set to true this helper calls normalizeResponse instead of extract.

All the built-in serializers get isNewSerializerAPI set to true automatically if the feature flag is enabled.

Module: ember-data
store
DS.Store
payload
Object
returns
DS.Model|Array

one or multiple records from data

Push a JSON-API Document to the store.

This will push both primary data located in data and secondary data located in included (if present).

Module: ember-data
store
DS.Store
payload
Object
returns
DS.Model|Array

one or multiple records from data

Push the primary data of a JSON-API Document to the store.

This method only pushes the primary data located in data.

Module: ember-data
store
DS.Store
payload
Object
returns
Array

an array containing zero or more records from included

Push the secondary data of a JSON-API Document to the store.

This method only pushes the secondary data located in included.

Module: ember-data
fixtures
Array
query
Object
typeClass
DS.Model
returns
(Promise|Array)

Implement this method in order to query fixtures data

Module: ember-data
store
DS.Store
type
subclass of DS.Model
query
Object
returns
Promise

promise

The queryRecord() method is invoked when the store is asked for a single record through a query object.

In response to queryRecord() being called, you should always fetch fresh data. Once found, you can asynchronously call the store's push() method to push the record into the store.

Here is an example queryRecord implementation:

Example

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

export default DS.Adapter.extend(DS.BuildURLMixin, {
  queryRecord: function(store, type, query) {
    var urlForQueryRecord = this.buildURL(type.modelName, null, null, 'queryRecord', query);

    return new Ember.RSVP.Promise(function(resolve, reject) {
      Ember.$.getJSON(urlForQueryRecord, query).then(function(data) {
        Ember.run(null, resolve, data);
      }, function(jqXHR) {
        jqXHR.then = null; // tame jQuery's ill mannered promises
        Ember.run(null, reject, jqXHR);
      });
    });
  }
});
Module: ember-data
snapshot
DS.Snapshot
options
Object
returns
Object

serialized snapshot

Proxies to the serializer's serialize method.

Example

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

export default DS.Adapter.extend({
  createRecord: function(store, type, snapshot) {
    var data = this.serialize(snapshot, { includeId: true });
    var url = type;

    // ...
  }
});
Module: ember-data
store
DS.Store
snapshotRecordArray
DS.SnapshotRecordArray
returns
Boolean

This method is used by the store to determine if the store should reload a record array after the store.findAll method resolves with a cached record array.

This method is only checked by the store when the store is returning a cached record array.

If this method returns true the store will re-fetch all records from the adapter.

Module: ember-data
store
DS.Store
snapshot
DS.Snapshot
returns
Boolean

This method is used by the store to determine if the store should reload a record after the store.findRecord method resolves a cached record.

This method is only checked by the store when the store is returning a cached record.

If this method returns true the store will re-fetch a record from the adapter.

Module: ember-data
store
DS.Store
snapshotRecordArray
DS.SnapshotRecordArray
returns
Boolean

This method is used by the store to determine if the store should reload all records from the adapter when records are requested by store.findAll.

If this method returns true, the store will re-fetch all records from the adapter. If this method returns false, the store will resolve immediately using the cached record.

Module: ember-data
store
DS.Store
snapshot
DS.Snapshot
returns
Boolean

This method is used by the store to determine if the store should reload a record from the adapter when a record is requested by store.findRecord.

If this method returns true, the store will re-fetch a record from the adapter. If this method returns false, the store will resolve immediately using the cached record.

Module: ember-data
typeClass
DS.Model
fixture
Array
Module: ember-data
store
DS.Store
typeClass
DS.Model
snapshot
DS.Snapshot
returns
Promise

promise

Module: ember-data
doc
Object

JSON API document

returns
Array

An array of errors found in the document structure

This is a helper method that validates a JSON API top-level document

The format of a document is described here: http://jsonapi.org/format/#document-top-level