In the below example I create a one-direction relation between two vertices (from b to a), is there a way I can create a relation from (a to b) at the same time?
SELECT *
FROM cypher('test_graph', $$
MATCH (a:Person), (b:Person) WHERE a.name = 'hossam' AND b.name = 'omar'
CREATE (b)-[r:REL {name: b.name+'->'+a.name}]->(a) RETURN r
$$) as (v agtype);
I tried remove the arrow symbol > before (a) like: CREATE (b)-[r:REL {name: b.name+'->'+a.name}]-(a)
but it results with a syntax error.
3
Answers
As of right now i believe the most straightforward way to achieve bidirectional relations is to set it as a property, you can’t just remove the direction at the moment of creation. For example:
this will return as you said the error
and the same thing will happen if you use bidirectional edge
You need to try something like this:
by assigning the "<->" as properties you can search search all the bidirectional relations in your graph using:
Since the feature of bidirectional relations isn’t yet supported I believe this is one way to get around that.
No, there is no way to create bidirectional relationships in Apache AGE.
There is no way to create bidirectional relationships in Neo4j either as written in the answers to this question. The reasoning being since you are allowed to make non-directional queries, bidirectional relationships become essentially same as disregarding the direction altogether.
On a more technical level:-
The edges are stored with a vertex start_id and an end_id in the edges table. Having bidirectional relationship means that both the start_id and the end_id need to have 2 values.
You have 2 alternatives:-
1.) Make another relationship in the opposite direction (however it takes more space).
2.) Make non-directional queries.
Create two relations in one go:
AGE ensures your graphs have a bi-directional relationship in terms of Edges.
Try the following query to check:
Returns:
The query for the opposite relation match
Returns:
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 followingb.name+'<->'+a.name