Batman.js:未找到用于多态关联的相关模型 [英] Batman.js: Related model undefined for polymorphic association not found

查看:99
本文介绍了Batman.js:未找到用于多态关联的相关模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在Batman模型上实现多态关联时遇到了一个问题.我在控制台中收到此错误:

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?

我的模型如下所示:

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

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

推荐答案

当Batman在关联中加载相关模型时,它将检查名称空间.默认情况下,名称空间为Batman.currentApp(调用MyApp.run()后的应用程序),但是在声明关联时也可以传递名称空间:

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

这样,蝙蝠侠将在Admin.Product而不是Admin上寻找PopularCollectable.

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

这篇关于Batman.js:未找到用于多态关联的相关模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆