15.4. Redirect relationships

15.4.1. Redirect Source Node

We start with two nodes related each other with a relationship. We create a new node which we will use to redirect the relationship like end node

CREATE (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
CREATE (p:Person {name:'Antony'})
RETURN *
apoc.refactor.to.dataset
MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar) with id(rel) as id
MATCH (p:Person {name:'Antony'}) with p as p
MATCH ()-[r]->(), (p:Person)  CALL apoc.refactor.to(r, p) YIELD input, output RETURN *
apoc.refactor.to

Now the relationship is towards the new node Person

15.4.2. Redirect Target Node

We start with two nodes related each other with a relationship. We create a new node which we will use to redirect the relationship like start node

CREATE (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
CREATE (p:Person {name:'Antony'})
RETURN *
apoc.refactor.from.dataset
MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar) with id(rel) as id
MATCH (p:Person {name:'Antony'}) with p as p
MATCH ()-[r]->(), (p:Person)  CALL apoc.refactor.from(r, p) YIELD input, output RETURN *
apoc.refactor.from

Now the relationship starts from the new node Person from the old node Bar