T
TypeDB4mo ago
cam

should it be possible to have two

should it be possible to have two attributes on an entity with an @key annotation? I somehow ended up in that situation hahaha
5 Replies
cam
camOP4mo ago
many entities are sub Versionable, Versionable owns contentHash @key, and then some entities that are sub Versionable also have an @key annotation
krishnan
krishnan4mo ago
The key is declared on the ownership. If you declare a owns b @key, then $a isa a,has b $b should return exactly one $b per $a. If separately a owns c @key, then $a isa a, has c $c should also return exactly one $c per $a.
georgii
georgii4mo ago
^ to elaborate, yes you can have as many keys as you want. They don't affect each other as long as not { c sub b; };. If c sub b;, both constraints will work on instances of c
krishnan
krishnan4mo ago
Was this the problem case?
a1 sub a;
b1 sub b; b2 sub b;
a owns b @key;
a1 owns b1 @key;
a1 owns b2 @key;
a1 sub a;
b1 sub b; b2 sub b;
a owns b @key;
a1 owns b1 @key;
a1 owns b2 @key;
georgii
georgii4mo ago
Yes, you require exactly one b, but you also require exactly one b1 and exactly one b2. Thus, you require at most one b and at least two bs at the same time

Did you find this page helpful?