Fork me on GitHub
#datomic
<
2020-08-18
>
mafcocinco13:08:10

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?

mafcocinco13:08:10

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?

favila13:08:37

Are you saying that the uniqueness constraint is expressed among the entities referenced?

favila13:08:16

so normal ref uniqueness is not enough, and the referenced entities themselves don’t have inherent uniqueness

favila13:08:42

would an example be: A person may have many addresses, but only one may be a primary address

favila13:08:24

or: A person may hold many cards, but they must all have the same color or different numbers

favila13:08:37

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

favila13:08:55

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

favila13:08:55

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

favila13:08:19

finally, you can just use a :db/ensure function that enforces your constraint

mafcocinco14:08:09

It is more the open set concept, so reversing the relationship might be the way to go, though I’m going to look at :db/ensure first.

mafcocinco14:08:17

Thank you for your help.

joshkh19:08:48

is there a path to audit access to a datomic cloud system, perhaps using cloudtrail?