The Store

One Identity Map for Your App's Records

The Store

The store is the entry point for Ember Data — findRecord, findAll, queryRecord, createRecord, and peek live here.

4 min read Level 2/5 #ember#ember-data#store
What you'll learn
  • Inject the store service
  • Use findAll and findRecord to fetch data
  • Use createRecord and save to add new entities

The store service is Ember Data’s front door. Every fetch, every new record, every query goes through it.

Inject It

import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class PostsRoute extends Route {
  @service store;

  async model() {
    return this.store.findAll('post');
  }
}

Reading

const all   = await this.store.findAll('post');
const one   = await this.store.findRecord('post', 42);
const recent = await this.store.query('post', { sort: '-createdAt' });
const cached = this.store.peekRecord('post', 42); // sync, cache-only

Creating

const draft = this.store.createRecord('post', {
  title: 'Hello',
  published: false,
});
await draft.save();      // POST /posts

createRecord returns a fully reactive model instance immediately — it has an auto-generated id until the server responds.

Updating

Just set attributes and save:

post.title = 'Updated';
await post.save();       // PATCH /posts/42

Use post.hasDirtyAttributes to detect unsaved changes and post.rollbackAttributes() to discard them.

Deleting

await post.destroyRecord(); // DELETE /posts/42

The record is removed from the store and any template referencing it re-renders.

findRecord, findAll & peekRecord →