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. |
Creating a relationship with dynamic types using Cypher
Relationship types can be referenced dynamically in Cypher without using APOC.
CREATE ()-[r:$(type)]->()
The dynamically calculated type must evaluate to a STRING
or LIST<STRING>
.
For more information, see the Cypher Manual → CREATE nodes and relationships using dynamic node labels and relationship types.
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"});
The example below demonstrates how to use APOC and Cypher to create a relationship by passing in its type and properties dynamically using parameters:
The following creates relType
and properties
parameters:
:param relType => ("ACTED_IN");
:param properties => ({roles: ["Joe Fox"]});
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;
MATCH (p:Person {name: "Tom Hanks"})
MATCH (m:Movie {title:"You've Got Mail"})
CREATE (p)-[rel:$($relType) $properties]->(m)
RETURN rel;
rel |
---|
[:ACTED_IN {roles: ["Joe Fox"]}] |