ember 数据中使用相同模型类型的多个关系
multiple relations using same model type in ember data
我有一个 account
模型,它具有以下内容:
export default Model.extend({
primaryStaff: belongsTo('staff'),
secondaryStaff: belongsTo('staff')
});
primaryStaff
映射到 account
模型上的 primaryStaffId
键,secondaryStaff
映射到 secondaryStaffId
。有没有办法让它们都指向 staff
模型?
运气不好。谢谢!
更新:
我正在使用 JSON API 适配器 -- 这是一个示例负载:
{
"data": {
"type": "account",
"id": "17",
"attributes": {
"businessId": 1,
"userId": 22,
"scopes": [
"customer",
"customer-22"
],
"keyCode": null,
"lockboxCode": null,
"notes": null,
"active": false,
"createdAt": "2017-01-31T20:13:39.465Z",
"updatedAt": "2017-02-20T03:49:17.308Z",
},
"relationships": {
"business": {
"data": {
"type": "business",
"id": "1"
}
},
"customer": {
"data": {
"type": "customer",
"id": "22"
}
},
"secondaryStaff": {
"data": null
},
"primaryStaff": {
"data": {
"type": "staff",
"id": "1"
}
}
}
}
}
您需要修改应用程序(或模型)序列化程序。
我有一个 account
模型,它具有以下内容:
export default Model.extend({
primaryStaff: belongsTo('staff'),
secondaryStaff: belongsTo('staff')
});
primaryStaff
映射到 account
模型上的 primaryStaffId
键,secondaryStaff
映射到 secondaryStaffId
。有没有办法让它们都指向 staff
模型?
运气不好。谢谢!
更新:
我正在使用 JSON API 适配器 -- 这是一个示例负载:
{
"data": {
"type": "account",
"id": "17",
"attributes": {
"businessId": 1,
"userId": 22,
"scopes": [
"customer",
"customer-22"
],
"keyCode": null,
"lockboxCode": null,
"notes": null,
"active": false,
"createdAt": "2017-01-31T20:13:39.465Z",
"updatedAt": "2017-02-20T03:49:17.308Z",
},
"relationships": {
"business": {
"data": {
"type": "business",
"id": "1"
}
},
"customer": {
"data": {
"type": "customer",
"id": "22"
}
},
"secondaryStaff": {
"data": null
},
"primaryStaff": {
"data": {
"type": "staff",
"id": "1"
}
}
}
}
}
您需要修改应用程序(或模型)序列化程序。