Create two relations in one go:
SELECT *
FROM cypher('test', $$
MATCH (a:Person), (b:Person) WHERE a.name = 'hossam' AND b.name = 'omar'
CREATE br =
(b)-[r:REL {name: b.name+'->'+a.name}]->(a)<-[r:REL {name: b.name+'<-'+a.name}]-(b)
RETURN br
$$) as (v agtype);
AGE ensures your graphs have a bi-directional relationship in terms of Edges.
Try the following query to check:
SELECT * FROM cypher('test_graph', $$ MATCH (a)-[r]->(b) RETURN r $$) as (v agtype);
Returns:
{"id": 9570149208162308, "label": "REL", "end_id": 9851624184872964, "start_id": 9851624184872963, "pro
perties": {"name": "omar->hossam"}}::edge
The query for the opposite relation match
SELECT * FROM cypher('test_graph', $$ MATCH (b)-[r]->(a) RETURN r $$) as (v agtype);
Returns:
{"id": 9570149208162308, "label": "REL", "end_id": 9851624184872964, "start_id": 9851624184872963, "pro
perties": {"name": "omar->hossam"}}::edge
If however you need the relation to be in the form of hossam->omar
. You'll need to define another relation, preferably from (a)-[r]->(b)
. And it will show up as another edge.
OR,
A better approach is to just imply the relation as the following b.name+'<->'+a.name