I have two vertex classes V1 and V2, both have the property 'id'. I have one edge class, E.
V1's id property is a unique index, so all V1 have unique ids. Now I want that all V2 instances connected to a certain V1 instance have unique ids. So:
OK (and needed to work)
V1(id:"A") ---- E ----> V2(id:"a")
V1(id:"A") ---- E ----> V2(id:"b")
V1(id:"B") ---- E ----> V2(id:"a")
V1(id:"B") ---- E ----> V2(id:"b")
Not OK
V1(id:"A") ---- E ----> V2(id:"a")
V1(id:"A") ---- E ----> V2(id:"a")
Preferably, as an addition, it should also be possible for V2 instances to exist without edges and they should then be unique in the global scope. If this last part is not possible, the first part is helpful anyways.
Is this possible by database configuration / indexing (on edge or vertices) or do I have to enforce it in the application?
UPDATE
What I mean with by configuration / indexing is that it would be prevented (exception) if you were trying to add the edge (just like when using a unique index to enforce that only one edge exists between two vertices).
I see only 2 ways to do this:
id
attribute in the edge and call it v2id
, so you can create an unique index against out
+ v2id
onBeforeCreate()
of class E and do your checks