我使用最新版本的ember-data遇到了多态关系问题。 基本上,ember没有将调用传递给多态模型。
以下是我的模特:
App.Movie = DS.Model.extend({
title: DS.attr('string'),
events: DS.hasMany('App.Event')
});
App.Event = DS.Model.extend({
time: DS.attr('number'),
movie: DS.belongsTo('App.Movie'),
eventable: DS.belongsTo('App.Eventable', { polymorphic: true })
});
App.Eventable = DS.Model.extend({
event: DS.belongsTo('App.Event')
});
App.Song = App.Eventable.extend({
title: DS.attr('string'),
artist: DS.attr('string')
});
App.Product = App.Eventable.extend({
title: DS.attr('string')
});
App.Place = App.Eventable.extend({
title: DS.attr('string')
});
store / Fixture适配器如下所示:
DS.FixtureAdapter.configure("App.Song", {
alias: 'song'
});
DS.FixtureAdapter.configure("App.Product", {
alias: 'product'
});
DS.FixtureAdapter.map('App.Movie', {
events: { embedded: 'load' }
});
DS.FixtureAdapter.map('App.Event', {
eventable: { embedded: 'load' }
});
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.FixtureAdapter
});
这是我的Fixture数据:
App.Movie.FIXTURES = [
{
title: "Reservoir Dogs",
id: "reservoir-dogs",
events : [ {
time: 3,
id: 155,
eventable: {
id: 2,
type: 'song',
title: 'Like a Virgin',
artist: 'Madonna'
}},
{
time: 30,
id: 155,
eventable_type: 'product',
eventable_id: 3,
eventable: {
id: 3,
type: 'product',
title: 'A Velvet Pillow'
}}
]
}
];
我在早期版本的ember-data中遇到了不同的问题,我升级尝试修复它,现在我点击了这个(希望当我解决这个问题时,我的另一个问题是也要固定!)
这是一个jsbin:http://jsbin.com/ewiqex/3/