3
votes

I'm trying to transfert all ingoing and outgoing relationships from a node to another, before deleting the first one. they both have the same label. I saw this Neo4j Cypher: copy relationships and delete node but in my case i don't know the type of the relations and i want to transfer both ingoing and outgoing ones.

i'm looking for either a cypher query or a query based on neo4j.rb

1

1 Answers

4
votes

I don't think that this is possible with pure cypher. Here's a solution using neo4j.rb that I think will work:

# Assuming node1 already loaded
node_query = Neo4j::Session.query.match(node: {neo_id: node1.neo_id})

types = node_query.match('node-[rel]-()').pluck('DISTINCT type(rel)')

types.each do |type|
  node_query.match('node-[rel]->(other)').with(:node, :rel, :other).create("node-[new_rel]->other").set('new_rel = rel').exec
  node_query.match('node<-[rel]-(other)').with(:node, :rel, :other).create("node<-[new_rel]-other").set('new_rel = rel').exec
end