【发布时间】:2017-12-13 21:36:44
【问题描述】:
我想尝试为我的 Ember 应用提供 sideloaded data。我有一个 city 模型 hasMany fireStations。我将我的 hasMany 关系更改为有一个 { async: false } 选项以配合侧加载,因为数据将不再异步加载。
我使用自定义序列化程序,并记录来自normalize() 的响应。我的数据看起来像这样。
{
"data": {
"id": "3",
"type": "city",
"attributes": {
"name": "Anytown USA"
},
"relationships": {
"fireStations": {
"data": [
{
"id": "17",
"type": "fire-station"
},
{
"id": "18",
"type": "fire-station"
}
]
}
}
},
"included": [
{
"id": "17",
"type": "fire-station",
"attributes": {
"name": "North Side Fire Station"
},
"relationships": {}
},
{
"id": "18",
"type": "fire-station",
"attributes": {
"name": "East Side Fire Station"
},
"relationships": {}
}
]
}
我认为我的侧载数据格式正确。它似乎与example in the guides 匹配。 included 数组中填充了我所有的侧载数据,并且似乎都根据需要进行了格式化。
但是,我在我的应用程序中遇到了这个错误。
断言失败:您在 id 为 3 的“城市”上查找了“fireStations”关系,但未加载一些相关记录。要么确保它们都与父记录一起加载,要么指定关系是异步的 ('DS.hasMany({ async: true })')
根据 JSON API 规范,我使用的格式似乎对于加载 compound documents 是正确的。
在复合文档中,所有包含的资源必须表示为顶级
included成员中的资源对象数组。
而且似乎links 是可选的,所以我将它们排除在外应该没问题。
每个资源对象中的可选
links成员包含与资源相关的链接。
我无法弄清楚这里的问题是什么。我在本地分叉了ember-data,我确实看到了this assertion is triggered。
如果我手动遍历has-many.js 中的manyArray,我会看到每条记录都标记为isEmpty,即true
为什么has-many 记录返回isEmpty === true?我可能做错了什么导致侧载无法正常工作?
【问题讨论】:
标签: ember.js ember-data