【问题标题】:undefined method `rels` for #<Neo4j::Core::Node:xxxxxxxx>#<Neo4j::Core::Node:xxxxxxxx> 的未定义方法`rels`
【发布时间】:2017-05-08 18:32:30
【问题描述】:

最近我升级到 Neo4j 3.1.3、Neo4j.rb 8.0.13 和 Neo4j-core 7.1.2。此后,rels 方法抛出undefined method 'rels' for #&lt;Neo4j::Core::Node:xxxxxxxx&gt; 错误。

我的问题是, student.rels(dir: :outgoing, type: :enrolled_in).count

除了rels 方法,create_rel 方法也不能正常工作。我一直在阅读文档以查看这两种方法是否已从较新版本中弃用,但到目前为止还没有运气。

【问题讨论】:

  • 没查过,试试relationships吧,Neo4j的其他部分也有这个动作,可能这个也有。
  • 现在错误已更改为:undefined method 'relationships' for #&lt;Student:xxxxxxxxxxx&gt;

标签: ruby-on-rails neo4j neo4j.rb


【解决方案1】:

在阅读此答案的其余部分之前,您可能需要阅读 upgrade guide

rels 关系未添加到替换旧 API 中旧 Node 对象的 Neo4j::Core::Node 对象中。我相信我们在ActiveNode 中也有一个rels 方法。

如果你使用ActiveNode,替换是定义一个关联。比如:

class Student
  include Neo4j::ActiveNode

  has_many :out, :all_nodes, type: :enrolled_in, model_class: false
end

# Then you can do:
student.all_nodes.count

但是,您只关注enrolled_in 关系这一事实让我认为这可能会针对特定节点(可能是Course?)。如果是这样,我建议这样做:

class Course
  include Neo4j::ActiveNode
end

class
  include Neo4j::ActiveNode
  has_many :out, :courses, type: :enrolled_in 
  # model_class of `Course` will be assumed based on the association's name
end

如果您不直接使用 ActiveNode 而是直接使用 neo4j-core gem,则应使用 Cypher 查询

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多