2012-01-03 11 views
0

Neo4jクラスのインスタンスからそのクラスの別のインスタンスに関係を作成する適切な方法は何ですか?Neo4jの自己関係

たとえば、他のコースに先行するコースのモデルを使用して、コースカタログのコースをモデリングしているとします。

私はレールとのNeo4j使用しています:

モデル:

クラスコース<のNeo4j :: Railsの::モデルのプロパティ:(:PREREQS).from(コース、:leadstos
has_nに名前を)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

あなたが宣言する必要があります。

has_n(:leadstos).to(Course) 
として関係leadtos
関連する問題