0

How to model Many-to-Many relationship in Graph databases (Property graph database)

In the below picture, Company/creditor files their claim to court when the borrower goes bankrupt and there will be an authorised representative for the each company/creditor to the case. How to model this scenario ?

Find who is representative of given creditor? Trick is creditor can have multiple claim on multiple case and multiple authorized representative.

Any suggestion ? If possible in Apache Tinkerpop Gremlin way of handling.

Many to Many Relationship

Thirumal
  • 8,280
  • 11
  • 53
  • 103

1 Answers1

0

Generally speaking, one option is to connect the Representative directly to the Case. This will eliminate the need to add a dynamic label (Although we don't know what you want to query yet).

On neo4j, it can be modeled like this:

MERGE (a:Representative {key: 1})
MERGE (b:Representative {key: 2})
MERGE (c:Representative {key: 3})
MERGE (d:Company{key: 1})
MERGE (e:Company{key: 2})
MERGE (f:Case{key: 1})
MERGE (g:Case{key: 2})

MERGE (a)-[:CASE]-(f)
MERGE (b)-[:CASE]-(g)
MERGE (c)-[:CASE]-(g)
MERGE (d)-[:CREDITOR]-(f)
MERGE (d)-[:CREDITOR]-(g)
MERGE (e)-[:CREDITOR]-(g)
MERGE (a)-[:CONTACT]-(d)
MERGE (b)-[:CONTACT]-(d)
MERGE (c)-[:CONTACT]-(e)

And look like this: graph

nimrod serok
  • 14,151
  • 2
  • 11
  • 33