Where are the records stored in Ember Data?, part 3

by Kasper Tidemann

With the release of Ember Data beta 1, the way records are stored locally changed once again, paving the way for a new blog post about how to currently find and inspect those records.

Adding a bit of context here, you might find yourself in a situation where you want to know if a record has been fetched already without actually fetching the record in case it’s not stored locally. This is a fairly common pattern in a handful of situations.

At the time of writing, it’s possible to get all the records of a given type stored locally via the typeMapFor function of the store. Here’s an example:

// ... some context that has access to the store:

var store = this.get('store');
var userModel = store.modelFor('user');
var userRecords = store.typeMapFor(userModel).records;

var someUser = userRecords.findProperty('id', 'someUserId');

The above will get all user records stored locally and then attempt to find a particular record by id via the findProperty function.

While this may not be the prettiest code, it will get the job done – and save you from keeping track manually.

Notice: this is a follow-up to the original post which is outdated by the time of writing.