0

I'd like to know if it is possible to create a Vertex that requires an edge in order to be created.

For example, I want to create an Invoice class that has a HasCustomer edge which points to Person.

I want the HasCustomer edge to be mandatory in order to create the Invoice.

You cannot create the Invoice unless you have the HasCustomer edge.

I know we can have a link to Person, but there is no referential integrity. I can delete the Person and the Invoice will simply end up with a link to a customer that is non-existent.

Yashpal Singla
  • 1,924
  • 4
  • 21
  • 38
  • 1
    That's a great question! I hope someone can help you with the answer. – Software Prophets Jul 14 '16 at 18:34
  • @OutfastSource Thanks, hope we get the answer – Yashpal Singla Jul 18 '16 at 08:08
  • I think this answer gives a clue: http://stackoverflow.com/questions/26274362/is-it-possible-to-constraint-edge-multiplicity-in-neo4j-orientdb/26278502#26278502 The element I'm interested in is the MIN constraint for a property. The problem I've encountered in working with this though is that the vertex needs to exist first and then the edge, or you have to create the edge and the 2 vertexes at the same time. By having the min on the vertex, the edge needs to be passed into the create vertex which I think is impossible. – Software Prophets Jul 18 '16 at 12:37
  • That isn't what the OP asked for, is it? He wants to be able to create a Vertex and have an Edge automatically created due to the Vertrex creation. This simply isn't possible with OOTB ODB. What you've gotten on to is edge multiplicity. This is possible, but not with property constraints as in the answer you linked to. Getting a unidirectional edge is better done with a unique index constraint (currently). See here: http://orientdb.com/docs/2.2/Tutorial-Using-schema-with-graphs.html – m8a Jul 20 '16 at 15:45

2 Answers2

1

In OrientDB, you have to create the edge yourself. So if you have the invoice vertex created, you then have to create the HasCustomer edge between the invoice and the customer.

However, if you delete that invoice vertex later, ODB will also remove the linked edge you created (and others) automatically, in order to keep up the data integrity (i.e no orphaned edges).

http://orientdb.com/docs/2.1/SQL-Delete-Vertex.html

This is also why you should choose the Graph API over the Document API. With the Document API, keeping up any integrity between links is up to you.

I am also not sure if it is possible, but you could theoretically create a server-side function, which triggers after any invoice vertex is created (onAfterCreation trigger), which could then create the HasCustomer edge automatically. Again, all theory on my part, as I've never done it before.

http://orientdb.com/docs/2.2.x/Functions.html http://orientdb.com/docs/2.2.x/Dynamic-Hooks.html

Scott

m8a
  • 682
  • 5
  • 11
0

Watching the official documentation, you can't do the operation that you have described. The only property mandatory you can use is on the fields on class or on edges. About use of the link, rightly as you said, missing control over referential integrity, this because to do this check is very expensive in terms of performance.

lsavio
  • 850
  • 4
  • 10