Neo4j.rb create unique relationship

亡梦爱人 提交于 2019-12-05 14:52:24

This is something we have an issue open for:

https://github.com/neo4jrb/neo4j/issues/473

For now I would suggest creating a method like this on the User model:

def create_unique_follower(other)
    Neo4j::Query.match(user: {User: {neo_id: self.neo_id}})
                .match(other: {User: {neo_id: other.neo_id}})
                .create_unique('user-[:following]->other').exec
end

EDIT: See mrstif's answer for an update

Just as an update, you can now do the following:

For simple relationships, use unique:true:

class User
  include Neo4j::ActiveNode
  has_many :out, :following, type: :following, model_class: 'User', unique: true
end

For declared relationships, use creates_unique:

class Following
  include Neo4j::ActiveRel

  creates_unique

  from_class User
  to_class   User
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!