2012-01-03 234 views
0

什麼是從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]}出現爲空白。

回答

2

你將不得不宣佈:leadtos關係作爲

has_n(:leadstos).to(Course)