Search code examples
orientdbdata-modelingobject-relationships

OrientDb edge between multiple vertex


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.


Solution

  • 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