我试图加载一个模拟Json,但是我得到了以下错误:
未明错误:断言失败:您在id 2的“post”上查找了“作者”关系,但是一些相关的记录没有加载。要么确保它们都与父记录一起加载,要么指定关系为异步(DS.belongsTo({ async: true }))。
这是来自http://localhost:4200/api/posts/2的JSON
{
"post":{
"id":2,
"title":"Monkeys",
"date":"2013-12-21T00:04:20.461Z",
"author":1,
"body":"Vestibulum porttitor leo maximustae ultricies risus efficitur sit amet."
},
"author":{
"id":1,
"name":"George",
"posts":[
2
]
}
}models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
date: DS.attr('date'),
author: DS.belongsTo('author')
});models/author.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
posts: DS.hasMany('post')
});发布于 2015-03-25 01:11:59
你试过这样嘲笑你的儿子吗?
{
"posts":[
{
"id":2,
"title":"Monkeys",
"date":"2013-12-21T00:04:20.461Z",
"author":1,
"body":"Vestibulum porttitor leo maximustae ultricies risus efficitur sit amet."
}
],
"author":{
"id":1,
"name":"George",
"posts":[
2
]
}
}错误状态为some of the associated records were not loaded。
https://stackoverflow.com/questions/29245732
复制相似问题