加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何在Mongoid中为子类设置集合名称?

发布时间:2020-12-16 23:30:42 所属栏目:百科 来源:网络整理
导读:class Foo include Mongoid::Documentendclass Bar Fooend Foo.all返回Bars,Bar.all返回Foos. 我想把Foo和Bar放在不同的集合中. 我试过了 class Bar Foo store_in collection: 'bars' 但得到了 Mongoid::Errors::InvalidStorageParent:Problem: Invalid stor
class Foo
  include Mongoid::Document
end

class Bar < Foo
end

Foo.all返回Bars,Bar.all返回Foos.

我想把Foo和Bar放在不同的集合中.

我试过了

class Bar < Foo
  store_in collection: 'bars'

但得到了

Mongoid::Errors::InvalidStorageParent:
Problem:
  Invalid store_in call on class Bar.
Summary:
  The :store_in macro can only be called on a base Mongoid Document

使用Mongoid 4.0.2

解决方法

您还需要将Bar设为Mongoid文档.
class Bar < Foo
  include Mongoid::Document
  store_in collection: 'bars'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读