2012-12-28 29 views
0

我遇到了试图在Batman模型上实现多态关联的问题。我在控制台中发现了这个错误:Batman.js:相关模型未定义多态关联未找到

相关模型undefined for polymorphic association not found。

我很难追查我出错的地方。我应该在哪里找到缺失的部分?

我的模型看起来是这样的:

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

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

回答

0

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

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

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

0

我能够当它被送到从Rails的客户端嵌入父蝙蝠侠Model实例内has_many关系的belongs_to侧来解决此问题:

format.json {render :json => @post, :include => {:comments => {:include => :comments}}}