apoc.convert.toRelationshipFunction
Syntax |
|
||
Description |
Converts the given value into a |
||
Arguments |
Name |
Type |
Description |
|
|
The value to convert into a relationship. |
|
Returns |
|
||
Example
Given this dataset:
CREATE (:Person {name: 'Alice'})-[:KNOWS {since: 2020}]->(:Person {name: 'Bob'})
The following query uses apoc.convert.toRelationship to cast a value extracted from a generic list back to a RELATIONSHIP:
MATCH ()-[r:KNOWS]->()
WITH collect(r) AS rels
RETURN apoc.convert.toRelationship(rels[0]) AS rel
| rel |
|---|
[:KNOWS {since: 2020}] |
The function returns null when passed null or a value that is not a RELATIONSHIP:
RETURN apoc.convert.toRelationship(null) AS nullInput,
apoc.convert.toRelationship('not a rel') AS wrongType
| nullInput | wrongType |
|---|---|
null |
null |