david8401
david8401

Reputation: 479

Ember-data: nested model properties access errors out

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.

Upvotes: 2

Views: 662

Answers (1)

david8401
david8401

Reputation: 479

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

Upvotes: 3

Related Questions