【发布时间】:2011-01-11 22:24:50
【问题描述】:
我正在使用mongoid-tree,但这个问题可能适用于其他acts_as_tree ports for Mongoid。
我想要一棵节点树,并且我想要将整个树嵌入到另一个文档中。我的问题是,这实际上只需要嵌入根节点,但所有节点都具有相同的embedded_in。就我而言:
class Container
include Mongoid::Document
embeds_one :root, :class_name => "Node"
end
class Node
include Mongoid::Document
include Mongoid::Tree
embedded_in :container, :inverse_of => :root
end
我该如何设置,以便每棵树只有一条记录嵌入到容器中?还有其他更好的方法吗?
【问题讨论】:
标签: ruby-on-rails mongodb mongoid