Neo4j自我关系
问题描述:
什么是从Neo4j类的实例到该类的另一个实例创建关系的正确方法?Neo4j自我关系
例如,如果我在课程目录中建模课程,并为其他课程提供预备课程的模型。
我使用的Neo4j与导轨:
型号:
类课程<的Neo4j ::导轨:: Model属性:名称
has_n(:prereqs)。从(场:leadstos )has_n(:leadstos)
创建对象和关系:
algebra = Course.create :name => 'algebra'
arithmetic = Course.create :name => 'arithmetic'
algebra.prereqs << arithmetic
algebra.save!
arithmetic.save!
algebra.prereqs.each {|node| puts node [:name]}
#prints 'arithmetic'
但是,arithmetic.leadstos.each {|node| puts node[:name]}
出现为空白。
答
你将不得不宣布:leadtos关系作为
has_n(:leadstos).to(Course)