【问题标题】:Neo4j self-relationNeo4j 自相关
【发布时间】:2012-01-03 17:24:44
【问题描述】:

创建从 Neo4j 类的实例到该类的另一个实例的关系的正确方法是什么?

例如,如果我在课程目录中为课程建模,其中的课程模型是其他课程的先决条件。

我正在使用带有 rails 的 neo4j:

型号:

类课程 has_n(:prereqs).from(Course, :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]} 显示为空白。

【问题讨论】:

    标签: ruby-on-rails neo4j


    【解决方案1】:

    您必须将 :leadtos 关系声明为

    has_n(:leadstos).to(Course)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      相关资源
      最近更新 更多