O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding records

Ember-data provides various ways to query loaded records as well to pull new ones from backend services. To find all records of a particular model, we can simply utilize the store's find method, as follows:

// GET /todos

store.find('todo');

This method loads all todos from the server via a promise that we then consume, shown as follows:

store
  .find('todo')
  .then(function(todos){
    todos.map(function(todo){
      todo.set('complete', false);
      return todo;
    });
  });

If we, however, want to only query loaded records, we can use the store's all method, as follows:

store.all('todo');

Similarly, we may want to query a record by a given id, as follows:

// GET /todos/1

store.find('todo', id);

Querying records by search terms is also as easy as:

// GET /todos?complete=true ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required