【问题标题】:Fetching HasMany Ember Relationship data asynchronously from Mirage从 Mirage 异步获取 HasMany Ember 关系数据
【发布时间】:2016-10-25 01:26:52
【问题描述】:

我有一个 hasMany 异步关系的模型,

export default Model.extend({
    name: attr(),
    description: attr(),
    metricNamespaces: hasMany('metric-namespace', {
        async: true
    })
});

这是一个模型实例的示例 jSONAPI 文档

{
  "data": {
    "type": "context",
    "id": "1",
    "attributes": {
      "name": "O'Reilly Inc",
      "description": "Aut mollitia mollitia esse inventore est consequatur mollitia ex dolores. Deserunt est dicta temporibus eius. Id dicta molestiae nostrum odio."
    },
    "relationships": {
      "metricNamespaces": {
        "data": [
          {
            "type": "metric-namespace",
            "id": "8"
          }
        ]
      }
    }
  }
}

我在尝试获取关系的路由中有一个 afterModel 钩子

model.get('metricNamespaces').then((success) => {
    console.log("Success", success);
}, (error) => {
    console.log("Error", error);
});

我希望这会触发对 Mirage 的获取请求。但这永远不会触发 get 请求(这应该会失败,因为我没有 metric-namespace get 的 mirage 路由)

谁能帮我弄清楚我错过了什么?

【问题讨论】:

  • 乍一看它应该可以工作......你有没有机会推出一个简化的回购来重现这个?

标签: ember.js ember-data ember-cli-mirage


【解决方案1】:

这是模型中的属性名称。必须将其从 metricNamespaces 更改为 namespaces 不知道为什么会解决它(也许骆驼案是问题所在)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多