Reputation: 1994
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.
Upvotes: 0
Views: 80
Reputation: 701
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
Upvotes: 1
Reputation: 850
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.
Upvotes: 0