Class Store

The store service contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates.

By default, applications will have a single Store service that is automatically created.

The store can be customized by extending the service in the following manner:

app/services/store.js
1
2
3
import Store from '@ember-data/store';

export default class MyStore extends Store {}

You can retrieve models from the store in several ways. To retrieve a record for a specific id, use the Store's findRecord() method:

1
2
store.findRecord('person', 123).then(function (person) {
});

By default, the store will talk to your backend using a standard REST mechanism. You can customize how the store talks to your backend by specifying a custom adapter:

app/adapters/application.js
1
2
3
4
import DS from 'ember-data';

export default Adapter.extend({
});

You can learn more about writing a custom adapter by reading the Adapter documentation.

Store createRecord() vs. push() vs. pushPayload()

The store provides multiple ways to create new record objects. They have some subtle differences in their use which are detailed below:

createRecord is used for creating new records on the client side. This will return a new record in the created.uncommitted state. In order to persist this record to the backend, you will need to call record.save().

push is used to notify Ember Data's store of new or updated records that exist in the backend. This will return a record in the loaded.saved state. The primary use-case for store#push is to notify Ember Data about record updates (full or partial) that happen outside of the normal adapter methods (for example SSE or Web Sockets).

pushPayload is a convenience wrapper for store#push that will deserialize payloads if the Serializer implements a pushPayload method.

Note: When creating a new record using any of the above methods Ember Data will update RecordArrays such as those returned by store#peekAll() or store#findAll(). This means any data bindings or computed properties that depend on the RecordArray will automatically be synced to include the new or updated record values.

Show:

The default adapter to use to communicate to a backend server or other persistence layer. This will be overridden by an application adapter if present.

If you want to specify app/adapters/custom.js as a string, do:

1
2
3
4
5
6
7
8
import Store from '@ember-data/store';

export default Store.extend({
  constructor() {
    super(...arguments);
    this.adapter = 'custom';
  }
}