polymorphic-associationsbatman.js

Batman.js: Related model undefined for polymorphic association not found


I'm running into an issue trying to implement polymorphic associations on a Batman model. I'm getting this error in the console:

Related model undefined for polymorphic association not found.

I'm having a hard time tracking down where I am going wrong. Where should I look to find the missing piece?

My models look something like this:

class Admin.Product.PopularCollectables extends Batman.Model
  @belongsTo 'collectable', polymorphic: true

class Admin.Item extends Batman.Model
  @hasOne 'popular_collectable', as: 'collectable'

Solution

  • When Batman loads a related model in an association, it checks a namespace. By default, the namespace is Batman.currentApp (which is your app after you call MyApp.run()), but you can also pass a namespace when you declare the association:

    class Admin.Item extends Batman.Model
      @hasOne 'popular_collectable', as: 'collectable', namespace: Admin.Product
    

    That way, Batman will look for PopularCollectable on Admin.Product instead of on Admin.