首先,您的工作小提琴,抱歉我将它移植到 jsbin,因为我更喜欢它,但这不会以任何方式影响功能:http: //jsbin.com/ifukev/2/edit
现在我已经改变了,基本上我所做的是定义 aApp.Author
有许多出版物并且 aApp.Publication
属于 aApp.Author
并完成了相应的 FIXTURES:
App.Author = DS.Model.extend({
name: DS.attr('string'),
publications: DS.hasMany('App.Publication'),
didLoad: function () {
console.log('Author model loaded', this);
}
});
App.Publication = DS.Model.extend({
title: DS.attr('string'),
bodytext: DS.attr('string'),
author: DS.belongsTo('App.Author'),
didLoad: function () {
console.log('Publication model loaded', this);
}
});
//FIXTURES DATA
App.Publication.FIXTURES = [
{
id: '1',
title: 'first title',
bodytext: 'first body',
author: 100
},
{
id: '2',
title: 'second title',
bodytext: 'second post',
author: 300
}
];
App.Author.FIXTURES = [
{
id: '300',
name: 'Marc',
publications: [2]
},
{
id: '100',
name: 'Jan',
publications: [1]
}
];
希望能帮助到你。