简体   繁体   中英

Neo4j gem - Create relationship between two nodes only if it doesn't exist

If I have two nodes ( self ) and friend_node , what's the most efficient way to do this check if I already know my two nodes.

I built this off of what you taught me last time but this seems convoluted given that I know where my nodes are. Is there anything easier?

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

假设用户上有一个名为friends的关联,那么user.friends.include?(friend_node)就是这样。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM