Neo4j gem - 只有在两个节点不存在的情况下才创建它们之间的关系

时间:2015-01-22 04:15:00

标签: ruby-on-rails neo4j relationship neo4j.rb

如果我有两个节点(self)和friend_node,那么最有效的方法是检查我是否已经知道我的两个节点。

我是根据你上次教我的内容建立起来的,但考虑到我知道节点在哪里,这似乎很复杂。还有什么比较容易了吗?

self.query_as(:user).match(friend: {uuid: friend_node.id}).where("NOT(user-[:friends_with]->(friend:User))").pluck(:friend) unless friend_node.blank?

1 个答案:

答案 0 :(得分:1)

假设名为friends的用户之间存在关联,请执行user.friends.include?(friend_node)