Where are the records stored in Ember Data?

by Kasper Tidemann

Notice: since the time of writing, this has been changed in Ember Data. Please take a look at this post instead.

When using Ember Data, you fetch a record by calling apple = App.Fruit.find('apple'). Of course, you now have an apple object, but where is the data actually stored?

Ember Data introduces the concept of buckets. The store has buckets for all records that are either clean, created, updated, deleted, or inflight. All buckets hide in the defaultTransaction of the store.

By calling App.store.get('defaultTransaction.buckets'), you will get all five buckets. Once you’ve successfully fetched the apple record, it will be inserted into the clean bucket. When you update one of the record’s properties, it will be moved to the updated bucket – and so on.

To get the actual records, you need look in the list array of a bucket. This can be achieved by calling App.store.get('defaultTransaction.buckets.clean.list'), resulting in an array of the clean records in the store.

If you want to get a list of all the ids of the records in a bucket, you can make use of the excellent mapProperty function. If you chain the function call like so, App.store.get('defaultTransaction.buckets.clean.list').mapProperty('id'), you will have an array of the ids returned: ['apple', 'banana', 'pear', 'orange'].

You should not manipulate the buckets by hand – that is, add or remove any records – as that would break Ember Data’s internal bookkeeping.

Now, if you’re trying to figure out if a record has been loaded without actually loading it (which would happen by calling App.Fruit.find('apple').get('isLoaded')), a plausible approach is to look for the record in the clean bucket instead.