Neo4j.rb 如何合并两个节点之间的关系

Neo4j.rb How to merge two realtionship between node

class User
  include Neo4j::ActiveNode

  has_many :in, :homes, origin: :owner
  has_many :in, :shared_homes, origin: :home_mates, model_class: 'Home'
end

class Home
  include Neo4j::ActiveNode

  has_many :out, :housemates, type: :home_mate, model_class: 'User'
  has_one :out, :owner, type: :owner_of, model_class: 'User'
end


# f_ids is array of users
@users = User.as(:c).where(uuid: f_ids)

# for homes
@homes = @users.homes(:p)

# for shared homes
@homes = @users.shared_homes(:p)

我想合并这两条记录,因为这两种类型的地方都将在 :p

中引用

任何解决方案我也在 neo4j.rb 中尝试在进入 cypher

之前做到这一点

我真的很想允许 has_one / has_manytype 选项支持一系列关系类型,这样你就可以做类似的事情:

has_many :in, :associated_homes, type: [:home_mates, :owner_of]

不幸的是,这还不可能,但你现在可以通过这个 hack 来创建诸如关联:

has_many :in, :associated_homes, type: 'home_mates`|`owner_of'

提示:User.as(:c).where(uuid: f_ids) 可以简单地是 User.where(id: f_ids)