问题1,,我在EMB-1.0.0-rc.1+ ember.data-11中创建嵌套模型的概念有什么问题?
问题2,使用var line = App.Line.find()的,我应该得到这个行。如何将Andon或Shift作为对象,嵌套在一行中?还是只有安东的颜色?
这是我的jsFiddle。
App.Line = DS.Model.extend({
name: DS.attr('string'),
shifts: DS.hasMany('App.Shift'),
});
App.Shift = DS.Model.extend({
name: DS.attr('string'),
// shift 1 <-> 1 shifts
line: DS.belongsTo('App.Line'),
// one-to-one relationship between Shift and Andon
andon: DS.belongsTo('App.Andon')
});
App.Andon = DS.Model.extend({
// one-to-one relationship between Shift and Andon
shift: DS.belongsTo('App.Shift')
})主计长
App.LinesController = Ember.ArrayController.extend({
content: [],
});
App.linesController = Ember.ArrayController.create({
content: [],
init: function(){
var self = this;
self.pushObject(
App.Line.createRecord(
{
...
shifts: [
App.Shift.createRecord(
{
andon: App.Andon.createRecord({...})
}),
App.Shift.createRecord(
{
andon: App.Andon.createRecord({...})
}),
]
},
],
}
),
);
},
});非常感谢!
发布于 2013-03-22 14:01:32
关于问题2:
我认为您需要为每个belongsTo添加一个外键,即Shift中的line_id和andon_id,以及Andon中的shift_id,然后您需要创建一些序列化器,在这里您可以嵌入/副业关联。不幸的是,我只熟悉rails中的activeModel序列化程序,在您的情况下可能无法使用这些序列化程序,但是这个问题的答案中的示例可能会对您有所帮助。
https://stackoverflow.com/questions/15520718
复制相似问题