ember:Model不能扩展另一个模型以进行多态关联

时间:2013-09-19 18:05:17

标签: ember.js ember-data

我正试图让多态关联起作用但到目前为止没有运气。基本上我希望该曲目属于播放列表和专辑

App.Playlist = App.Trackable.extend

App.Album = App.Trackable.extend

App.Trackable = DS.Model.extend
  tracks: DS.hasMany 'track'

App.Track = DS.Model.extend
  title: DS.attr 'string'
  trackable: DS.belongsTo('trackable',
    polymorphic: true)

但后来我收到以下错误

Uncaught TypeError: Cannot call method 'extend' of undefined

1 个答案:

答案 0 :(得分:1)

我认为你订单错了。您正在尝试扩展尚未声明的模型。试试这个:

App.Trackable = DS.Model.extend
  tracks: DS.hasMany 'track'

App.Playlist = App.Trackable.extend

App.Album = App.Trackable.extend

App.Track = DS.Model.extend
  title: DS.attr 'string'
  trackable: DS.belongsTo('trackable',
    polymorphic: true)