0

I am trying to model data for OrientDB. I am new to graph-database. I got doubt during modeling (paradigm change from RDBMS to GraphData).
How model tertiary (3-way i.e. between 3-vertex) relationship in Graph database (OrientDB)? An example is as below:

  1. Customer A introduces Customer B to Bank C.
  2. Employee A has referred Employee B and Employee C in Company D.
  3. Fiend A introduces Friend B to friend C.
  4. Person A is Granter of the Loan account of Person B in Mortgage company C.
  5. Person A & B has purchased policy type 'Life-Insurance' of Insurance Company 'MetLife' from Agent C.

Currently, I am using a vertex in between (like Introduction-Process) and edges to all related vertex

('IntroducedBy'-edge between 'Customer A' and 'Inroduction-Process'; 'IntroducedTo'-edge between 'Customer B' and 'Inroduction-Process' and 'IntroducedFor'-edge between 'Bank C' and 'Inroduction-Process').

Is it correct or is there any other option?

How to represent a enumeration value? As for example Customer-account-type. Currently I have created a class of AccountType and has fixed number of vertex (same as of Enum values) and create a link from Account to AccountType. Is there any better option to model the Enumeration in Graph-database?

Thanks in advance.

Priyantha
  • 4,839
  • 6
  • 26
  • 46

2 Answers2

1

What you are referring to is called a Hypergraph

All the main graph databases in the market (including OrientDB) do not implement hypergraph capabilities, so you have to use a vertex in between, as you are donig now.

For the enumeration, your approach could be correct, but you will quickly end up with supernodes (vertices with a lot of connections), that is not something you want.

In most cases you don't need a full fledged vertex to represent and enumeration value, a string (or a number) is typically enough. In OrientDB, to constrain a property to a limited set of values, you can define a validation rule in the schema (eg. a regular expression), see http://orientdb.com/docs/2.2.x/SQL-Alter-Property.html

Luigi Dell'Aquila
  • 2,804
  • 10
  • 13
  • Thanks Luigi and Amin. I will continue to use extra vertex in case of 3-way relationship. For Enum values, I am now using 2-approaches: 1. If the enum values are supposed to change, I am using LINK property as suggested by Amin. 2. If the enum is very much fixed, I am using string value with RegExp constrain. – Meghnad Mahata Nov 24 '17 at 04:59
1

Instead of creating these edges, can't you use LINKSET datatype? That will help you store the required reference without creating extra edges.

I am new to OrientDB and might be wrong but I ran into the super node problem as mentioned by @Luigi and solved it using the LINKSET.

In my case it was a medical database with prescriptions and medicines and some of the commonly used medicines where creating a super node.

Amin Baig
  • 411
  • 4
  • 26
  • 1
    Yes, when you have unidirectional relationships using linksets is ok. But please consider that OrientDB does not manage referential integrity for links and linksets, so if you delete a linked record, the link won't be removed (it will just point to nothing). The other obvious disadvantage is that links can be traversed in one direction only – Luigi Dell'Aquila Nov 24 '17 at 08:58