1
votes

I'm running Ember 1.0 with Ember Data 1.0 Canary using FixtureAdapter. One of my routes will load its model correctly the first time I enter it, but any subsequent time the data will be empty. Here is that route:

App.PlannerRoute = App.AuthenticatedRoute.extend({
  model: function() {
    var snapshotId,
        scenarioController = this.controllerFor('scenario'),
        snapshot = scenarioController.get('selectedSnapshot'),
        scenario = scenarioController.get('content');
    if ( !snapshot ) {
      if ( !scenario )
        this.transitionTo('scenarios');
      else
        this.transitionTo('scenario', scenario);
    }
    snapshotId = snapshot.get('id');
    return Ember.Object.create({
      regions: this.store.find('region', { snapshot: snapshotId }),
      networks: this.store.find('networks', { snapshot: snapshotId }),
      terminals: this.store.find('terminals', { snapshot: snapshotId })
    });
  }
});

If I set a break point at the return statement in the model method above, I find that the calls to this.store.find always retrieve the correct data. However, the data is only populated into the route's controllers/views/templates/etc on the first transition to the route.

Any assistance in tracking down the problem is appreciated. How can I fix this?

1
First thing I would try is using the latest builds of Ember and EmberData.gerry3
Seeing similar behavior with hasMany children. After building and saving a number of parent child graphs everything looks like through Ember debug tool in store. I can see the children in hasMany sets of parent. If I then run store.findAll('parent') those hasMany sets become [].Rob Ottaway
@gerry3 I am using ember-date (Last commit: 3017027 (2013-09-27 22:45:12 -0700)), ember (Last commit: a186eff (2013-09-27 22:53:46 -0700)) seeing very similar behavior.Rob Ottaway

1 Answers

0
votes

Have you tried something like:

...
snapshotId = snapshot.get('id');
var regions = this.store.find('region', { snapshot: snapshotId }),
    networks = this.store.find('networks', { snapshot: snapshotId }),
    terminals = this.store.find('terminals', { snapshot: snapshotId });

return Ember.RSVP.all([ regions, networks, terminals ]).then(function(results){
  return Ember.Object.create({
    regions: results[0],
    networks: results[1],
    terminals: results[2]
  });
});