我遇到了一个问题,试图在蝙蝠侠模型上实现多态关联。我在控制台中得到了这个错误:
未找到未定义的多态关联相关模型。
我很难找出我哪里出了问题。我应该在哪里找丢失的那件东西?
我的模特们看起来是这样的:
class Admin.Product.PopularCollectables extends Batman.Model
@belongsTo 'collectable', polymorphic: true
class Admin.Item extends Batman.Model
@hasOne 'popular_collectable', as: 'collectable'发布于 2013-11-19 05:50:29
当蝙蝠侠在关联中加载相关模型时,它会检查名称空间。默认情况下,名称空间是Batman.currentApp (这是您调用MyApp.run()之后的应用程序),但是您也可以在声明关联时传递名称空间:
class Admin.Item extends Batman.Model
@hasOne 'popular_collectable', as: 'collectable', namespace: Admin.Product这样,蝙蝠侠就会在Admin.Product而不是Admin上寻找Admin.Product。
发布于 2013-06-09 12:35:11
当从Rails发送到客户端时,我能够通过在父蝙蝠侠模型实例中嵌入has_many关系的has_many端来解决这个问题:
format.json {render :json => @post, :include => {:comments => {:include => :comments}}}https://stackoverflow.com/questions/14076502
复制相似问题