我正试图让多态关联起作用但到目前为止没有运气。基本上我希望该曲目属于播放列表和专辑
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
答案 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)