Fork me on GitHub
#datomic
<
2020-01-04
>
Paul09:01:11

What is the idiomatic way to model relationships with varying types in datomic?

Paul09:01:09

Or more generally are there good resources with example how to model more complex problems in datomic?

favila17:01:03

What do you mean by varying types?

fmnoise19:01:22

If you mean attribute which may be a string or keyword or long or something else, then string field with EDN content may work, but such approach may also indicate bad architecture decision 🙈 I used that in real-world project to abstract system configuration:

[{:db/ident       :setting/name
  :db/valueType   :db.type/keyword
  :db/unique      :db.unique/identity
  :db/cardinality :db.cardinality/one}
 {:db/ident       :setting/value
  :db/valueType   :db.type/string
  :db/cardinality :db.cardinality/one}]

fmnoise19:01:20

if you talk about attribute which is reference to another entity then there's nothing to model, as references are not typed

favila02:01:06

For polymorphic attributes I like the pattern of having an attribute whose value is the attribute where the value may be found, liked a tagged union

favila02:01:22

Eg {:my/foo :my/fooLong, :my/fooLong 123}

favila02:01:03

For “polymorphic” refs you can either do the same or just use one attr and tag the referent instead

favila02:01:24

Entities are just bags of assertions and have no type, so just “type” them as far as is useful.

favila02:01:06

For polymorphic attributes I like the pattern of having an attribute whose value is the attribute where the value may be found, liked a tagged union