cancel
Showing results for 
Search instead for 
Did you mean: 

Prevent creating a relationship if it will create a cycle

li3zhang
Node Link

When creating an app like a family tree, I want to prevent the user from creating relationships that will create a cycle. Is it possible to tell if a transaction will create a cycle before committing?

1 REPLY 1

llpree
Graph Buddy

li3zhang, welcome to the community! Love the question as I love graph theory

Given a family tree is a directed graph (i.e., a father of a son is not a son to a father for the same two nodes), getting a cycle will be impossible. Certainly, someone's cousin can be another persons brother and this can result in a "cycle" if you ignore direction and relationship type. But I would contend that finding cycles by ignoring relationship type and direction would be very useful and desired in terms of insights in your tree - especially before the royal wedding

Am I missing something or is that helpful?

HTH

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.