从Sideloading防止Ember JSONAPISerializer

时间:2016-06-13 23:11:43

标签: ember.js ember-data

我正在使用一个使用外部API的Ember应用程序,而我的序列化程序出现问题。

我的应用程序正在提取用户帐户,但只关心用户帐户的基础知识。 API正在发布更多数据,这会带来麻烦。具体来说,它包含了一个与我不包含在我的Ember App中的模型的关系(因为它不适合域名)。

我正在尝试配置我的应用,以便它只是忽略API中的includedrelationship信息,但甚至尝试从序列化工具normalize中的响应中删除它们钩不工作。它一直试图查找未写入的模型,显然,失败了。同样,我查看了使用DS.EmbeddedRecordsMixin,但似乎仍然依赖于在我的应用程序中实现相关模型,我真的希望避免这种模式!

如何让JSONAPISerializer忽略关系并阻止它试图从included对象侧载数据?

为了更好地显示我的情况,这是一个示例有效负载:

{
  "jsonapi": {
    "version": "1.0"
  },
  "included": [
    {
     ...references models my app doesn't have
    }
  ],
  "data": {
    "type": "account",
    "relationships": {
      "permissions": {
        "data": [
          ...references the included object
        ]
      },
    },
    "id": "16",
    "attributes": {
      ...this is the information I *do* care about
     }
  }
}

ETA: 我的用户模型:

// app/models/account.js
export default Model.extend(Validations, {
  birthdate: attr('date'),
  email: attr('string'),
  firstName: attr('string'),
  lastName: attr('string'),
  profile: belongsTo('profile')
}

0 个答案:

没有答案
相关问题