Emond Jodiyosa
Emond Jodiyosa

Reputation: 69

Neo4j - How to design graph database based on type and / or level of relation

For example in the work environment, family, community, etc. Example:

On the A side, B is the Boss - On the B side, A is the Subordinate.
On the C side, D is the Teacher - On the D side, C is the student.
On the E side, F is Father - On the F side, E is a child.
On the E side, D is the Teacher - On the D side, E is the student.

Attributes such as superiors, subordinates, teachers, students, fathers, children, and so on can at any time increase, change and delete.

Upvotes: 0

Views: 29

Answers (1)

cybersam
cybersam

Reputation: 67019

You can use 3 relationship types to represent your "relations". For example, REPORTS_TO, HAS_STUDENT, HAS_CHILD:

(a)-[:REPORTS_TO]->(b)
(d)-[:HAS_STUDENT]->(c)
(f)-[:HAS_CHILD]->(e)
(d)-[:HAS_STUDENT]->(e)

While it is true that a neo4j relationship (e.g., of type HAS_STUDENT) must be created with a specific direction (e.g., from a teacher node to a student node), it can be just as easily (and efficiently) traversed in the opposite (or either) direction when you make a query.

Upvotes: 1

Related Questions