0
votes

I'm trying to get a app to work using the ember data 1.0 beta release and having issues getting the route to trigger a find the associated models loaded from a server.

Here's what my objects look like:

App.Technician = DS.Model.extend({
  first_name: DS.attr(),
  last_name: DS.attr(),
  name: function(){
    return this.get('first_name')+' '+this.get('last_name');
  }.property('first_name', 'last_name')
});

App.TechniciansRoute = Ember.Route.extend({
  model: function() {
    return this.get('store').find('technician');
  }
});

However when the technicians route tries to load the model the this.get('store').find() always throws an exception that find is not defined. I've debugged into it and hit the following function

store: Ember.computed(function(){
    var container = this.container;
    var routeName = this.routeName;
    var namespace = get(this, 'router.namespace');

    return {
      find: function(name, value) {
        var modelClass = container.lookupFactory('model:' + name);

        Ember.assert("You used the dynamic segment " + name + "_id in your route "+ routeName + ", but " + namespace + "." + classify(name) + " did not exist and you did not override your route's `model` hook.", modelClass);

        return modelClass.find(value);
      }
    };
  })

modelClass is an reference to App.Technician which does not have find() defined on it, and hence the execption is throw.

Does anyone have any ideas? it feels like I'm missing something simple but I can't figure out what it is.

2

2 Answers

2
votes

Try to use this.store.find(...) instead of this.get('store').find(...):

App.TechniciansRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('technician');
  }
});

Hope it helps.

0
votes

intuitivepixel lead me down the right path but basically what was happening was a dependency loading issue.

I am using require.js to load my dependencies and what was happening is I didn't have ember-data as a dependency before my Application.create was being called. This caused the Application.initializers to never be triggered on the application objects I was creating as the initializes were not added untill my data models and routes were being loaded.

so long story short. Makes sure ember-data is loaded before calling Ember.Application.create();