我有一位模范老师,他有很多学生。模型定义如下:
App.Teacher = DS.Model.extend({
email: DS.attr('string'),
students: DS.hasMany('student')
});
App.Student = DS.Model.extend({
teacher: DS.belongsTo('teacher'),
});
当教师登录时,服务器会返回教师的 JSON 表示形式:
{
id: 1,
email: "[email protected] /cdn-cgi/l/email-protection",
links: {
students: /teacher/1/students
}
}
在登录控制器中,我将这些数据推送到存储中并将其存储在会话控制器的属性中:
this.set('currentUser', this.get('store').push('teacher', teacherJson))
我想延迟加载students
因此我使用了 API 中定义的“链接”格式(http://emberjs.com/api/data/classes/DS.Store.html#method_push http://emberjs.com/api/data/classes/DS.Store.html#method_push)。所以,理想情况下,每当我打电话时
App.SessionController.get('currentUser').get('students')
它将加载关联的students
通过发送 GET 请求到/teacher/1/students
。但这永远不会发生。为什么请求没有被触发?