1

我正在尝试使多态关联起作用,但到目前为止还没有运气。基本上我希望这首歌属于播放列表和专辑

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
4

1 回答 1

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)
于 2013-09-19T19:08:01.140 回答