I'm trying to load fixtures into my app that has embedded records.
Loading the data from the server (using a DS.RESTAdapter
) works, but it does not when I try to load them through the DS.FixtureAdapter
.
Models:
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.
Adapter:
App.Adapter = DS.FixtureAdapter.extend()
App.Adapter.map App.Post,
comments:
embedded: 'always'
Store:
App.store = DS.Store.create
revision: 11
adapter: App.Adapter.create()
Fixtures:
App.Comment.FIXTURES = []
App.Post.FIXTURES = [
{
id: "1"
title: "My post"
comments: [{
id: "1"
text: "My first comment"
}, {
id: "2"
text: "My second comment"
}]
}
]
And in the console:
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
I think this question is related to this question, and maybe to this pull request.
Ember version used:
- ember-data on master
- ember v1.0.0-pre.2-311-g668783a
EDIT
Here is the JSFiddle that illustrate the problem. And I also wrote a failing test here.