2

I'm facing a strange issue accessing nested model properties in my handlebars template.
My JSON feed looks like this:

{
"hic": {
    "id": "1",
    "tree": {
        "id": "1",
        "folder": [
            {name: "test1"},
            {name: "test2"}
        ]
    ...
    }
}
}

When I try to display my folder objects via the following handlebars template:

<ul>
    {{#with tree}}
        {{#each folder}}
            <li>{{name}}</li>
        {{/each}}
    {{/with}}
</ul>

it errors out with: Uncaught TypeError: Cannot call method 'hasOwnProperty' of undefined.

This workaround brings the desired result.

<ul>
    {{#with tree.data.hasMany}}
        {{#each folder}}
            <li>{{name}}</li>
        {{/each}}
    {{/with}}
</ul>

Is this an issue with ember-data or am I doing something wrong?

Note: I wasn't able to reproduce the issue in a jsfiddle. When I create the Hic-model via createRecord() everything works as expected.

The json-feed can be found here. Thats my app.js. I can also provide a full node.js-project.

david8401
  • 379
  • 1
  • 3
  • 11
  • I'm a real ember newbie, but is there some kind of convention saying that "folder" should be plural in your json? Maybe that's why folders are not accessible? Just a guess... – Robin Jan 15 '13 at 17:06
  • I configured in *app.js* that the plural of folder is folder: `DS.Adapter.configure('plurals', { hic: 'hic', tree: 'tree', folder: 'folder' });`. – david8401 Jan 15 '13 at 17:31
  • could you add the id for tree in the json feed please ? – sly7_7 Jan 15 '13 at 22:28
  • The [json feed](http://dl.dropbox.com/u/42353723/hic.json) does include ids for all element/models. I just forgot to mention it in the sample above. – david8401 Jan 16 '13 at 07:45

1 Answers1

3

Root cause seems to be the embedded belongsTo-relationship. This pull request fixes this issue: Extract embedded belongsTo records properly. Many thanks to sandstrom!

david8401
  • 379
  • 1
  • 3
  • 11