I have custom and working models with toIt / hasMany relation:
App.User = DS.Model.extend({ name: DS.attr('string'), workspace: DS.belongsTo('App.Workspace') }); App.Workspace = DS.Model.extend({ name: DS.attr('string'), users: DS.hasMany('App.User') });
I have a controller setup and a view when the controller model property is set to a valid user.
App.ApplicationRoute = Ember.Route.extend({ setupController: function() { this.controllerFor('test').set('model', App.User.find(1)); } });
The following code and output shows that the belongsTo association was not loaded at runtime. What is the correct way to access a workspace (through a user) from a view class?
App.TestView = Ember.View.extend({ didInsertElement: function() { var self = this; console.log('first try: '); console.log(this.get('controller.model.workspace')); setTimeout(function() { console.log('second try: '); console.log(self.get('controller.model.workspace')); }, 1000); } });
Outputs;
// first try: // null // second try: // Class { ... }
I can access the workspace in the template via {{model.workspace}} - how can I do the same in the view class?
source share