What is an idiomatic way to express uniqueness within a set of attribute values in Datomic? That is, if I have an attribute that is of type
db.type/ref and it is of
db.cardinality/many, how do I enforce a uniqueness constraint on the set of values that is being referred to, in the context of the containing value?
Are you saying that the uniqueness constraint is expressed among the entities referenced?
so normal ref uniqueness is not enough, and the referenced entities themselves don’t have inherent uniqueness
would an example be: A person may have many addresses, but only one may be a primary address
or: A person may hold many cards, but they must all have the same color or different numbers
if there’s a fixed number of different states like in the address example, you can break up the single card-many attribute into more attributes with more specific meanings. e.g. instead of :person/addresses, you have :person/address-primary, :person/address-secondaries
if the set is more open (e.g. color or number constraints) but the entities are semantically “components” of the primary entity, you can reverse the direction of reference so the component points to the primary entity, then make a unique composite tuple that includes the component and the other attributes that mark uniqueness
if the referenced entities are not components (i.e. are shared among other entities, so you can’t add an ownership attribute to it), you have to do this through an intermediate entity
finally, you can just use a
:db/ensure function that enforces your constraint
It is more the open set concept, so reversing the relationship might be the way to go, though I’m going to look at
Thank you for your help.
is there a path to audit access to a datomic cloud system, perhaps using cloudtrail?1👍