-
If you return a promise
beforeModel
,model
, andafterModel
in a route, it will wait to resolve thepromise
before transitioning into the route. This is helpful when using loading and error substate templates. -
All ember data records go into a global cache. There is not a cache per query, nor is there a way to isolate that data per query. IE If you do a
this.store.query("gummy-bear", { account_id: "yummy-gummy" })
and then dothis.store.findAll("gummy-bear”)
. ThefindAll
will send a request to the server with those params, but since there have been records loaded into the store for "gummy-bear" they will be returned with the newly fetched (scoped) records from the server.
-
findRecord
- This replaces normalfind
(without query params). With the default caching behavior this will first respond with what is in the cache (if applicable) and then reload the data in the backgroundthis.get('store').findRecord('account', 1); // => returns promise for the record defaults to { reload: false, backgroundReload: true }
-
findAll
- This replacesfind
without an id. This is the method you should use to find acollection
of a records for a given type. With the default caching behavior this will first respond with what is in the cache (if applicable) and then reload data from the server in the background.this.get('store').findAll('account'); // => returns promise for the records defaults to { reload: false, backgroundReload: true }
-
queryRecord
- This replacesfind
(with query params when an id is supplied) This will always grab fresh data from the server and will not return the record from the global cache.this.get('store').queryRecord('account', 1, { active: true }); // => hits /accounts/1?active=true. Does not return data from the global cache
-
query
- This replacesfind
(with query params without an id supplied) This will always grab fresh data from the server and will not include any records that are in the global cache.this.get('store').query('account', { active: true }); // => hits /accounts?active=true. Does not return data from the global cache
- First time
store.findRecord
orstore.findAll
is called, fetch new data - Any time after return cached data from the global ember-data cache
- In background, update cached data to align with server, possibly add new records (basically what does the server return). note this occurs in the background unless told otherwise.
-
reload
: whentrue
ember-data will go grab fresh data from the server and wait.default
isfalse
(causing a background reload)this.get('store').findRecord('account', 1); // => reloaded in background record1 this.get('store').findRecord('account', 1, { reload: true }); // => waits for record1 to reload to resolve. Best way to show fresh data in the UI
-
backgroundReload
: whenfalse
the data will not update in the background. this is done onsettings
pages where you don't want settings to be jumpy by updating data later.this.get('store').findRecord('account', 1); // => reloaded in background record1. Will show the record, and then will update in the UI. this.get('store').findRecord('account', 1, { backgroundReload: false }); // => does not update record1 in the background. Will not change in the ui until you do a findRecord again.
-
peekRecord
- does not make a request to the server, returns the record if it is in the global cache, null if there is nothing in the cachethis.get('store').peekRecord('account', 1); // => record1 this.get('store').peekRecord('account', 2); // => null (because we have no record 2)
-
peekAll
- does not make a request to the server, returns all of the records in the global cache for a given typethis.get('store').peekAll('account'); // => [record1] this.get('store').peekAll('account'); // => [] (when there are no records in the global cache)