0
다음 클래스가 주어지면 노드가 다른 노드 (예 : parent_node
및 child_nodes
)와 다 대다 관계를 가질 수 있습니까?많은 모델을 참조하는 모델입니까?
class Node
include MongoMapper::Document
key :text, String
end
다음 클래스가 주어지면 노드가 다른 노드 (예 : parent_node
및 child_nodes
)와 다 대다 관계를 가질 수 있습니까?많은 모델을 참조하는 모델입니까?
class Node
include MongoMapper::Document
key :text, String
end
자녀가 둘 이상의 부모를 가질 수 있습니까? 그렇지 않으면, 많은/belongs_to는 잘 작동합니다 :
class Node
include MongoMapper::Document
key :text, String
key :parent_node_ids, Array, :typecast => 'ObjectId'
many :parent_nodes, :in => :parent_node_ids, :class_name => 'Node'
# inverse of many :in is still forthcoming in MM
def child_nodes
Node.where(:parent_node_ids => self.id)
end
end
# ... or store an array of child_node_ids instead ...
class Node
include MongoMapper::Document
key :text, String
key :child_node_ids, Array, :typecast => 'ObjectId'
many :child_nodes, :in => :child_node_ids, :class_name => 'Node'
# inverse of many :in is still forthcoming in MM
def parent_nodes
Node.where(:child_node_ids => self.id)
end
end
은 당신이 찾고있는 무엇인가요
class Node
include MongoMapper::Document
key :text, String
key :parent_node_id, ObjectId
belongs_to :parent_node, :class_name => 'Node'
many :child_nodes, :foreign_key => :parent_node_id, :class_name => 'Node'
end
노드가 여러 부모를 가질 수 있다면 ...?