The Store Service

Ember Data's Store, Injected Like Any Service

The Store Service

The store service gives you findRecord, query, createRecord, and friends anywhere in the app.

4 min read Level 2/5 #ember#ember-data#store
What you'll learn
  • Inject the store in services and components
  • Use createRecord and save for new entities
  • Use peekAll for cached collections

store is just another service — register and inject it like anything else. That symmetry is why Ember Data feels native: data access is the same shape as auth, routing, or any cross-cutting concern.

Inject Anywhere

import Component from '@glimmer/component';
import { service } from '@ember/service';

export default class NewPostForm extends Component {
  @service store;
  @service router;

  async createDraft() {
    const post = this.store.createRecord('post', {
      title: 'Untitled',
    });
    await post.save();
    this.router.transitionTo('post.edit', post.id);
  }
}

In Other Services

// app/services/cart.js
import Service, { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

export default class CartService extends Service {
  @service store;

  @tracked items = [];

  async checkout() {
    const order = this.store.createRecord('order', {
      items: this.items,
    });
    await order.save();
    this.items = [];
  }
}

peekAll For Synchronous Reads

When you need a fast, cache-only read — for a count badge, a filter pane — use peekAll:

<span>{{this.store.peekAll "notification" length}} unread</span>

peekAll returns a live record array. As records flow into the store (from any other request), the badge updates automatically.

Filtering In Memory

A common pattern is loading once and filtering with a getter:

get publishedPosts() {
  return this.store.peekAll('post').filter((p) => p.published);
}

Because peekAll is reactive, the filter re-runs when the cache changes — no manual refresh required.

The Session Service →