我使用commit eaa1123(ember)和508479d(ember-data)来构建JS文件.
我从我的Rails后端返回了以下JSON,它是使用active_model_serializers(0.6.0)生成的:
{
"posts": [
{
"id": 408,
"title": "Lorem Ipsum",
"body": "In at quo tempora provident nemo.",
"comments": [
{
"id": 956,
"body": "Quo incidunt eum dolorem."
},
...
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
和以下Ember型号:
App.Post = DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
comments: DS.hasMany('App.Comment', {
embedded: true
})
});
App.Comment = DS.Model.extend({
body: DS.attr('string'),
post: DS.belongsTo('App.Post')
});
Run Code Online (Sandbox Code Playgroud)
一切看起来都很正常:
post = App.Post.find(408);
post.get('title')
// => "Lorem Ipsum"
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法得到评论:
comments = post.get('comments')
comments.get('firstObject') instanceof App.Comment
// …Run Code Online (Sandbox Code Playgroud)