Redirect relationships
The APOC library contains procedures that can be used to redirect relationships to target nodes.
Procedures for redirecting relationships
Qualified Name | Type |
---|---|
|
Procedure |
|
Procedure |
Examples
The below examples will further explain this procedure.
Redirect Target Node
The following creates Foo and Bar nodes that are connected by a
FOOBAR
relationship, as well as a solitary Antony node:CREATE (f:Foo {value: "Foo"})-[rel:FOOBAR {a:1}]->(b:Bar {value: "Bar"})
CREATE (p:Person {name:'Antony'})
RETURN *
The following will change the target node of the
FOOBAR
relationship from the Bar node to the Antony node:MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
MATCH (p:Person {name:'Antony'})
CALL apoc.refactor.to(rel, p)
YIELD input, output
RETURN input, output
If the above query is run, it will result in the following graph:
Redirect Source Node
The following creates Foo2 and Bar2 nodes that are connected by a
FOOBAR2
relationship, as well as a solitary David node:CREATE (f:Foo2 {value: "Foo2"})-[rel:FOOBAR2 {a:1}]->(b:Bar2 {value: "Bar2"})
CREATE (p:Person {name:'David'})
RETURN *
The following will change the source node of the
FOOBAR2
relationship from the Foo node to the David node:MATCH (f:Foo2)-[rel:FOOBAR2 {a:1}]->(b:Bar2)
MATCH (p:Person {name:'David'})
CALL apoc.refactor.from(rel, p)
YIELD input, output
RETURN input, output
If the above query is run, it will result in the following graph: