【问题标题】:Neo4j.rb How to merge two realtionship between nodeNeo4j.rb 如何合并节点之间的两个关系
【发布时间】:2016-12-23 19:25:00
【问题描述】:
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 中尝试过的任何解决方案

【问题讨论】:

    标签: ruby-on-rails neo4j.rb


    【解决方案1】:

    我真的很想允许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'
    

    Protip:User.as(:c).where(uuid: f_ids) 可能只是 User.where(id: f_ids)

    【讨论】:

    • 再次感谢,User.as(:c) 我需要进一步链接查询
    • 很公平! ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多