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.
convertResourceObject (payload) Object
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:295
- 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.
createRecord (store, typeClass, snapshot) Promise
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:225
- store
- DS.Store
- typeClass
- DS.Model
- snapshot
- DS.Snapshot
- returns
- Promise
promise
deleteRecord (store, typeClass, snapshot) Promise
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:259
- store
- DS.Store
- typeClass
- DS.Model
- snapshot
- DS.Snapshot
- returns
- Promise
promise
find (store, typeClass, id, snapshot) Promise
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:134
- store
- DS.Store
- typeClass
- DS.Model
- id
- String
- snapshot
- DS.Snapshot
- returns
- Promise
promise
findAll (store, type, sinceToken, snapshotRecordArray) Promise
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:124
- 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
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);
});
});
}
});
findMany (store, typeClass, ids, snapshots) Promise
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:159
- store
- DS.Store
- typeClass
- DS.Model
- ids
- Array
- snapshots
- Array
- returns
- Promise
promise
findRecord (store, type, id, snapshot) Promise
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:87
- 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:
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);
});
});
}
});
fixturesForType (typeClass) Array
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:61
- typeClass
- DS.Model
- returns
- Array
Implement this method in order to provide data associated with a type
generateIdForRecord (store) String
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:125
- store
- DS.Store
- returns
- String
id
groupRecordsForFindMany (store, snapshots) Array
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:434
- 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.
mockJSON (store, typeClass, snapshot)
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:113
- store
- DS.Store
- typeClass
- DS.Model
- snapshot
- DS.Snapshot
Implement this method in order to provide json for CRUD methods
normalizeResponseHelper (serializer, store, modelClass, payload, id, requestType) Object
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:71
- 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.
pushPayload (store, payload) DS.Model|Array
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:222
- 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).
pushPayloadData (store, payload) DS.Model|Array
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:239
- 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
.
pushPayloadIncluded (store, payload) Array
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:263
- 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
.
queryFixtures (fixtures, query, typeClass) (Promise|Array)
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:83
- fixtures
- Array
- query
- Object
- typeClass
- DS.Model
- returns
- (Promise|Array)
Implement this method in order to query fixtures data
queryRecord (store, type, query) Promise
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:190
- 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
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);
});
});
}
});
serialize (snapshot, options) Object
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:260
- snapshot
- DS.Snapshot
- options
- Object
- returns
- Object
serialized snapshot
Proxies to the serializer's serialize
method.
Example
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;
// ...
}
});
shouldBackgroundReloadAll (store, snapshotRecordArray) Boolean
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:513
- 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.
shouldBackgroundReloadRecord (store, snapshot) Boolean
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:492
- 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.
shouldReloadAll (store, snapshotRecordArray) Boolean
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:472
- 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.
shouldReloadRecord (store, snapshot) Boolean
Inherited from DS.Adapter packages/ember-data/lib/system/adapter.js:454
- 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.
updateFixtures (typeClass, fixture)
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:96
- typeClass
- DS.Model
- fixture
- Array
updateRecord (store, typeClass, snapshot) Promise
Defined in packages/ember-data/lib/adapters/fixture-adapter.js:242
- store
- DS.Store
- typeClass
- DS.Model
- snapshot
- DS.Snapshot
- returns
- Promise
promise
validateDocumentStructure (doc) Array
Inherited from DS.Adapter packages/ember-data/lib/system/store/serializer-response.js:12
- 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