apoc.create.relationship
Syntax |
|
||
Description |
Creates a |
||
Input arguments |
Name |
Type |
Description |
|
|
The node from which the outgoing relationship will start. |
|
|
|
The type to assign to the new relationship. |
|
|
|
The properties to assign to the new relationship. |
|
|
|
The node to which the incoming relationship will be connected. |
|
Return arguments |
Name |
Type |
Description |
|
|
The created relationship. |
Usage Examples
The examples in this section are based on the following graph:
CREATE (p:Person {name: "Tom Hanks"})
CREATE (m:Movie {title:"You've Got Mail"});
This procedure provides a more flexible way of creating relationships than Cypher’s CREATE
clause.
The example below shows equivalent ways of creating a node with the Person
and Actor
labels, with a name
property of "Tom Hanks":
MATCH (p:Person {name: "Tom Hanks"})
MATCH (m:Movie {title:"You've Got Mail"})
CALL apoc.create.relationship(p, "ACTED_IN", {roles:['Joe Fox']}, m)
YIELD rel
RETURN rel;
MATCH (p:Person {name: "Tom Hanks"})
MATCH (m:Movie {title:"You've Got Mail"})
CREATE (p)-[rel:ACTED_IN {roles:['Joe Fox']}]->(m)
RETURN rel;
rel |
---|
[:ACTED_IN {roles: ["Joe Fox"]}] |
But this procedure is mostly useful for creating relationships that have a dynamic relationship type or dynamic properties. For example, we might want to create a relationship with a relationship type or properties passed in as parameters.
The following creates relationshipType
and properties
parameters:
:param relType => ("ACTED_IN");
:param properties => ({roles: ["Joe Fox"]});
The following creates a relationship with a relationship type and properties based on the previously defined parameters:
MATCH (p:Person {name: "Tom Hanks"})
MATCH (m:Movie {title:"You've Got Mail"})
CALL apoc.create.relationship(p, $relType, $properties, m)
YIELD rel
RETURN rel;
rel |
---|
[:ACTED_IN {roles: ["Joe Fox"]}] |