Neo4j.rb如何合并节点之间的两个实现

时间:2016-12-23 19:25:01

标签: ruby-on-rails neo4j.rb

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

在转到cypher之前,我还试图在neo4j.rb中做任何解决方案

1 个答案:

答案 0 :(得分:2)

我真的想允许type / has_one的{​​{1}}选项支持一系列关系类型,以便您可以执行以下操作:

has_many

不幸的是,这还不可能,但你现在可以通过这个黑客来创建这样的关联:

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

Protip:has_many :in, :associated_homes, type: 'home_mates`|`owner_of' 可能只是User.as(:c).where(uuid: f_ids)