Mexxer
Mexxer

Reputation: 1777

ember: Model can't extend another model for polymorphic association

I'm trying to get polymorphic associations to work but had no luck so far. Basically I wanted the track to belong to playlist AND album

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)

But then I get the following error

Uncaught TypeError: Cannot call method 'extend' of undefined

Upvotes: 1

Views: 306

Answers (1)

chopper
chopper

Reputation: 6709

I think you have the order wrong. You're trying to extend models that you have not declared yet. Try this:

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)

Upvotes: 1

Related Questions