0

我在尝试在蝙蝠侠模型上实现多态关联时遇到了问题。我在控制台中收到此错误:

未找到多态关联的相关模型未定义。

我很难找出哪里出错了。我应该在哪里寻找丢失的部分?

我的模型看起来像这样:

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

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

2 回答 2

0

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

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

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

于 2013-11-19T05:50:29.167 回答
0

当它从 Rails 发送到客户端时,我能够通过在父 Batman Model 实例belongs_to中嵌入关系的一侧来解决这个问题:has_many

format.json {render :json => @post, :include => {:comments => {:include => :comments}}}
于 2013-06-09T12:35:11.237 回答