You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by lvca April 10, 2023
Recently asked on Discord, but discussed in many other topics and issues, we'd need a way to create constraints for edges so they can be attached only to specific vertex types.
The most natural way to achieve this is to mimic what OrientDB does: create constraints on out and in properties. While in OrientDB out and in are real properties in the document, with ArcadeDB are managed in binary form (much faster), but then exposed to the users as respectively @out and @in metadata.
To provide constraints on edge we could simply allow the following syntax alter property Friend.@out linkedtype Account;alter property Friend.@in linkedtype Account (in OrientDB was LINKEDCLASS). This would mean Friend edge type can only connect Account to another Account.
CREATE EDGE TYPE HasParts
CREATE PROPERTY HasParts.`@out` link OF Product
CREATE PROPERTY HasParts.`@in` link OF Component
You can now set constraints also for LIST, MAP, and EMBEDDED. Example (part of the test suite):
create document type Invoice
create document type Product
CREATE PROPERTY Invoice.products LIST of Product
CREATE PROPERTY Invoice.tags LIST of String
CREATE PROPERTY Invoice.settings MAP of String
CREATE PROPERTY Invoice.mainProduct LINK of Product
CREATE PROPERTY Invoice.embedded EMBEDDED of Product
The validation if polymorphic. So in the example above, Invoice.products is a LIST of Product, but you can also insert any sub-type of Product
If the constraint is not validated, a ValidationException is thrown
There is no support for ALTER PROPERTY right now, so the linked type must be defined at creation time. To apply updates, just drop and re-create the property (changes to the schema don't update the records)
Because the properties don't exist in the schema. If don't exist, they are considered as simple RID. But keep in mind @out and @in are not regular properties but hardcoded in the vertex/edge records.
Activity
lvca commentedon Jul 18, 2023
In the end I used just
of:You can now set constraints also for LIST, MAP, and EMBEDDED. Example (part of the test suite):
lvca commentedon Jul 18, 2023
I forgot 3 things:
Invoice.productsis aLISTofProduct, but you can also insert any sub-type of ProductValidationExceptionis thrownALTER PROPERTYright now, so the linked type must be defined at creation time. To apply updates, just drop and re-create the property (changes to the schema don't update the records)feat: support for constraint on edges out/in + LINK, EMBEDDED, LIST a…
lvca commentedon Jul 18, 2023
It's 100% implemented under the
mainbranch. @gramian could you please help with the docs of this new part?Also, now that we have such constraints, Studio could display a UML-like diagram of types and relationships.
gramian commentedon Jul 18, 2023
Very cool. I help with the docs, too.
gramian commentedon Jul 18, 2023
About your
hasPartsexample: Why do I have toCREATE@inand@outproperties and not useALTER?lvca commentedon Jul 18, 2023
Because the properties don't exist in the schema. If don't exist, they are considered as simple RID. But keep in mind
@outand@inare not regular properties but hardcoded in the vertex/edge records.lvca commentedon Jul 18, 2023
Docs are in place, thanks @gramian. Closing the issue.
chore(deps): bump the github-actions group with 2 updates [skip ci]
feat: support for constraint on edges out/in + LINK, EMBEDDED, LIST a…
chore(deps): bump the github-actions group with 2 updates [skip ci]