I’m loading App.Structure objects using ember-data’s fixtures adapter. These objects have embedded App.Overlay objects as a hasMany relationship, like this:
App.Structure = DS.Model.extend({
name: DS.attr('string'),
// hash of overlay paths
overlays: DS.hasMany('App.Overlay', { embedded: true }),
});
App.Overlay = DS.Model.extend({
view: DS.attr('string'),
path: DS.attr('string')
});
App.Overlay.FIXTURES = [];
App.Structure.FIXTURES = [{
"id": 0,
"name": "Test Structure",
"overlays": [{
"view": "Isometric",
"path": "[elided to save space]"
}],
}];
(Note that the empty fixtures array is to fix this issue.)
Now I can load the App.Structure, but I can’t get anything out of it. See this jsfiddle; the Structure can be accessed, and it’s able to iterate over the overlays array, but the object(s) in the array are hollow shells with nothing in them.
Here’s a console session picking at this:
> currStructure = App.fixtureStore.findAll(App.Structure).get('firstObject');
Class
> currStructure.get('name');
"Test Structure"
> currStructure.get('overlays').get('length');
1
> var overlay = currStructure.get('overlays').get('firstObject');
undefined
> overlay instanceof App.Overlay;
true
> overlay.get('view');
null
> overlay.get('path');
null
Why is this not working?
ETA: following @Kristaps’ response, I’ve updated the fiddle. Now the first Overlay is still just a hollow shell, but any subsequent overlays aren’t. Huh?
I guess it is because you are not setting structure_id in overlay object and belongsTo relationship in Overlay object. See fiddle
http://jsfiddle.net/kristaps_petersons/REtNV/
and fixtures: