neo4jrb - 从节点保存 ActiveRel 属性

neo4jrb - Save ActiveRel property from node

我有一个像这样的 ActiveNode:

class Nodeexample
  include Neo4j::ActiveNode

  property :name

  validates :name, :presence => true

  has_many :in, :nodeexamples, rel_class: :SomeRel

end

和这样的 ActiveRel 模型:

class SomeRel
  include Neo4j::ActiveRel

  property :some_number, type: Float

  from_class :Nodeexample
  to_class :Nodeexample

  type :SOME_REL
  validates :some_number, :presence => true

end

我正在尝试弄清楚如何在 ActiveRel 模型中添加 "some_number" 属性:

node1 = Nodeexample.new(name:"node1")
node2 = Nodeexample.new(name:"node2")

#how can I add the "some_number" property in the ActiveRel class from here?
node1.nodes << node2

node1.save

我知道的唯一方法是先保存两个节点,然后保存关系,但我想一次保存所有,可以吗?保存 100 个节点然后保存 500 个关系很奇怪:(

您应该可以使用 create 方法来做到这一点:

node1 = Nodeexample.new(name:"node1")
node2 = Nodeexample.new(name:"node2")

node1.nodes.create(node2, some_number: 123)

使用 <<create

时,不需要 node1.save