LINK type constraints on lightweight edges
See original GitHub issueIs it possible to create LINK type constraints on a lightweight edge? I am running OrientDB 2.1.11, and I set my edges to be lightweight using the command
ALTER DATABASE CUSTOM useLightWeightEdges = TRUE
The following is an example of what I would like to be able to do.
I first ran the following SQL commands
CREATE CLASS C1 EXTENDS V
CREATE CLASS C2 EXTENDS V
CREATE CLASS E1 EXTENDS E
CREATE PROPERTY E1.out LINK C1
CREATE PROPERTY E1.in LINK C1
CREATE VERTEX C1 set id="c11"
CREATE VERTEX C1 set id="c12
CREATE VERTEX C2 set id="c2
After all that, now running
CREATE EDGE E1 FROM (SELECT FROM C1 WHERE "id" = "c11") TO (SELECT FROM C2 WHERE "id" = "c2")
does not throw any exceptions, and creates the edge as requested. Is there any reason why a lightweight edge cannot enforce LINK type constraints? If I make E1 a “normal” edge then the constraint is enforced and I get thrown an OValidationException
as I expected. Is creating a normal edge the only solution to my problem? Can lightweight edges also be configured to enforce such constraints?
I should mention, when I type
INFO CLASS E1
the LINK type constraint does show up on the output, which suggests to me that the constraint information for the lightweight edge is maintained by the database, even if not ultimately enforced. Thanks for any comments.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (9 by maintainers)
Top GitHub Comments
Thanks @smolinari and @nagarajasr for the comments and additional information.
I did some investigation on this looking into the source code for version 2.1.14 during the past couple of days. Essentially, all schema constraints (including LINK type) are completely ignored when the lightweightedges option for the db is set to “true”. This is what @nagarajasr was implying I suppose, and you can observe this in the code by looking at the implementation of getType() method of the OrientEdge class.
But you can’t also set these constraints on the two endpoint vertex classes. I feel this is reasonable as it is an edge type constraint, and it would not make sense to set constraints on the vertex end points without the edge being involved in any way.
So if my understanding is correct, this is more of a “not implemented now” thing (if it will ever be) rather than a bug. Part of the problem with implementing this seems to be that the constraint validation checks are done at a document level, and of course lightweight edges have no document by themselves. Validating a lightweight edge is really validating a property of another document (link property of either the out or in vertex), and may need a special case handling.
Thanks Luigi,
I believe we are only looking for the constraint between two vertex classes being upheld properly. In other words (using this section of the docs for an example).
http://orientdb.com/docs/2.1/Tutorial-Using-schema-with-graphs.html#using-in-and-out-constraints-on-edges
The control should not only be the direction of the edge (a car can’t own a person), but the fact that an “owns” edge can only be used between the “person” and “car” classes. If I would want to have multiple “owns” edges to other classes, then I wouldn’t add the “owns.in” property.
I hope that makes sense.
Scott