我有几个模型设置如下:
WT.WorkoutPlan = DS.Model.extend({
workouts: DS.hasMany('planWorkout'),
name: DS.attr()
});
WT.PlanWorkout = DS.Model.extend({});
当我尝试使用以下JSON加载模型时,锻炼加载正常,plan.get('name');
返回名称更正证明,但plan.get('workouts')
总是有0个成员。任何人都知道为什么协会没有加载?
这是JSON:
{
"planWorkouts": [
{
"id": 991,
"name": "Lower Body"
}
],
"workoutPlan": {
"id": 343,
"name": "male-20to39-fat-loss",
"planWorkouts": [991]
}
}
我正在使用ember-data 1.0beta3
答案 0 :(得分:2)
这个
"workoutPlan": {
"id": 343,
"name": "male-20to39-fat-loss",
"planWorkouts": [991]
}
应该是
"workoutPlan": {
"id": 343,
"name": "male-20to39-fat-loss",
"workouts": [991]
}
又称关键应该是训练,而不是你的json中的planWorkouts
答案 1 :(得分:0)
锻炼计划应该包含锻炼ID,你也可以通过在哈希中添加“锻炼”来加载锻炼,记住:锻炼生活在exercisePlan root hash之外。
{
"workoutPlan": {
"id": 1,
"name": "male-20to39-fat-loss"
"workout_ids": [ 1 ]
},
"workouts": [
{ "id": 1, "body": "what a dumb post" }
]
}