レコードが埋め込まれているアプリにフィクスチャをロードしようとしています。
サーバーからのデータのロード(を使用DS.RESTAdapter
)は機能しますが、を介してデータをロードしようとすると機能しませんDS.FixtureAdapter
。
モデル:
App.Post = DS.Model.extend
title: DS.attr('string')
comments: DS.hasMany('App.Comment')
App.Comment = DS.Model.extend
text: DS.attr('string')
# I'm not specifying DS.belongsTo('post') because comments could also exist
# with other objects.
# Anyway, it does not work even with it.
アダプタ:
App.Adapter = DS.FixtureAdapter.extend()
App.Adapter.map App.Post,
comments:
embedded: 'always'
店:
App.store = DS.Store.create
revision: 11
adapter: App.Adapter.create()
備品:
App.Comment.FIXTURES = []
App.Post.FIXTURES = [
{
id: "1"
title: "My post"
comments: [{
id: "1"
text: "My first comment"
}, {
id: "2"
text: "My second comment"
}]
}
]
そしてコンソールで:
post = App.store.find(App.Post, 1);
comments = post.get("comments");
console.log(comments.get('length')); // => 1
firstComment = comments.get('firstObject');
console.log(firstComment.get('id')); // => undefined
console.log(firstComment.get('name')); // => TypeError: Cannot call method `hasOwnProperty` of undefined
この質問はこの質問に関連していると思います。おそらくこのプルリクエストに関連していると思います。
使用した残り火バージョン:
- 残り火-マスターのデータ
- 残り火v1.0.0 -pre.2-311-g668783a
編集