0
votes

I'm using Ember 1.4 with EmberData beta 7. The routes in my application are fairly straight forward and looks like this. ScenarioController and StratsControllers are ArrayControllers. StratsStratController is an ObjectController.

 App.Router.map(function () {
    this.route('scenarios', {path: "/scenarios"});
    this.resource('strats', {path: "/"}, function() {
        this.route('strat', {path: "/strat/:strat_id"});
    });
 });

When I first transitioned into the 'strats' route, Ember calls the findAll method, which makes a request to my server for all 'strat' instances as expected. My server returns all data associated with the 'strat' model, side loading all related hasMany records. Then I transitioned to the scenarios route, and Ember calls findAll to fetch all 'scenario' instances, which was also as expected. However, when I transitioned back to the 'strats' route via the browser's back button, I see another GET message from Ember to my server requesting all 'strat' instances again. This surprised me. Why did Ember make another call to findAll for the 'strat' instances when it already has it in DS.store? Is this expected behavior?

1

1 Answers

0
votes

I think its because its a live array of data, so ember checks to see if anything has changed in the mean time. You can change the data to a static array using the toArray() method but the way it is currently means that any updates to the database are automatically reflected on the client.
I have just come across this in the docs:

FINDING ALL RECORDS OF A TYPE
1

var posts = this.store.find('post'); // => GET /posts

To get a list of records already loaded into the store, without making another network request, use all instead.

1

var posts = this.store.all('post'); // => no network request

find returns a DS.PromiseArray that fulfills to a DS.RecordArray and all directly returns a DS.RecordArray.

It's important to note that DS.RecordArray is not a JavaScript array. It is an object that implements Ember.Enumerable. This is important because, for example, if you want to retrieve records by index, the [] notation will not work--you'll have to use objectAt(index) instead.