I have a model Teacher which has many Students. The models are defined as follows:
App.Teacher = DS.Model.extend({
email: DS.attr('string'),
students: DS.hasMany('student')
});
App.Student = DS.Model.extend({
teacher: DS.belongsTo('teacher'),
});
When a Teacher logs in, the server returns a JSON representation of the Teacher:
{
id: 1,
email: "[email protected]",
links: {
students: /teacher/1/students
}
}
In the controller for login, I then push this data into the store and store it in a property of the Session controller:
this.set('currentUser', this.get('store').push('teacher', teacherJson))
I want to lazy-load the students
association so I used the "links" format as defined in the API (http://emberjs.com/api/data/classes/DS.Store.html#method_push). So, ideally, whenever I would call
App.SessionController.get('currentUser').get('students')
it would load the associated students
by sending a GET request to /teacher/1/students
. But that never happens. Why is the request not triggered?
Ok, I found the answer. I had to add a property async: true
to the students
association in the model for Teacher
:
App.Teacher = DS.Model.extend({
email: DS.attr('string'),
students: DS.hasMany('student', { async: true })
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With