Skip to content

Instantly share code, notes, and snippets.

@kurko
Last active December 22, 2015 02:59
Show Gist options
  • Save kurko/6407582 to your computer and use it in GitHub Desktop.
Save kurko/6407582 to your computer and use it in GitHub Desktop.
Ember.js bug with nested models
<h1>{{name}}</h1>
Client's name shows up fine. But campaigns don't :(
<br />
{{content.campaigns}} => <DS.ManyArray:ember374>
<br />
{{#each content.campaigns}}
No donut. Nothing shows up here. Using debugger, I can't
access firstObject nor anything. It's as if campaigns was
simply empty.
{{/each}}
// models
Admin.Client = DS.Model.extend({
name: DS.attr('string'),
campaigns: DS.hasMany('campaign')
});
Admin.Campaign = DS.Model.extend({
title: DS.attr('string'),
client: DS.belongsTo('client')
});
// router
Admin.ClientRoute = Ember.Route.extend({
// Without overriding this, Ember errors out on 1.0.0
model: function(params) {
return this.store.find('client', params.client_id);
}
});
{
"campaigns": [{
"id":8,
"title":"aaaa"
}],
"client": {
"id":18,
"name":"bebebe",
"campaign_ids":[8]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment