在ember数据中使用相同模型类型的多个关系

时间:2017-02-20 04:25:42

标签: ember.js ember-data

我有account模型,其中包含以下内容:

export default Model.extend({
  primaryStaff: belongsTo('staff'),
  secondaryStaff: belongsTo('staff')
});

primaryStaff映射到primaryStaffId模型上的account键,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"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您需要修改应用程序(或模型)序列化程序。

请查看this twiddle