Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating bi-directional relation between two nodes using the neo4jphp function "relateTo"

Tags:

neo4j

neo4jphp

I create a relationship as the following in Neo4php

$src->relateTo($dst, 'FRIENDS')
    ->setProperty('duration', '5')
    ->save();

I want the relationship be undirected not directed. If I am not wrong we can do this in Cypher

create n-[:FRIENDS]-m

vs

create n-[:FRIENDS]->m

How about in Neo4jphp? Can we set "relateTo" to a bi-directional relationship?

like image 585
user1848018 Avatar asked Jan 18 '26 10:01

user1848018


1 Answers

Neo4j does not support undirected relationships. What you are asking for is impossible. Why do you want undirected relationships? If the direction doesn't make sense for your domain, just pick a direction arbitrarily and ignore it when traversing or querying.

like image 62
Josh Adell Avatar answered Jan 21 '26 02:01

Josh Adell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!