我使用Rails 3.2.2与mongoid 2.4.6.为了保持我的集合小,我使用"store_in"语句将子对象存储在sepparate集合中的基类中.我的代码看起来像这样:
class BaseClass
include Mongoid::Document
end
class ChildClass1 < BaseClass
store_in :child_1
end
class ChildClass2 < BaseClass
store_in :child_2
end
Run Code Online (Sandbox Code Playgroud)
似乎对象随机存储在或其他子集合中.Child1类型的对象有时会存储在集合Child2中.这是我在日志中看到的令人惊讶的事情:
Started POST "/child_class_1" for 127.0.0.1 at 2012-05-22 10:22:51 -0400
Processing by ChildClass1Controller#create as HTML
MONGODB (0ms) myproject_development['child_2'].insert....
Run Code Online (Sandbox Code Playgroud)
它来自哪里?这是mongoid,rails还是mongodb中的错误?
inheritance ruby-on-rails multiple-inheritance mongodb mongoid