Fork me on GitHub
#datascript
<
2022-07-24
>
seepel00:07:41

Can I specify a unique reverse relation like this?

[{:dom/client-id #:db{:cardinality :db.cardinality/one,
                     :valueType :db.type/ref,
                     :unique :db.unique/identity}
 {:dom/_attr+key #:db{:cardinality :db.cardinality/one,
                     :valueType :db.type/tuple,
                     :tupleAttrs [:dom/_attr :dom/attr-key],
                     :unique :db.unique/identity}}
if I am providing data like this?
{:dom/client-id "9fadb8a6-dfdc-40a7-84b0-9f2eef552345"
 :dom/attr #:dom-attr{:key "client-id",
                       :value "9fadb8a6-dfdc-40a7-84b0-9f2eef552345"}}

seepel00:07:08

My first example may not have been the best as client-id appears in two spots. Here is an example of storing an h1 tag in the db

[{:dom/type "heading",
  :client/id "9cc3dd5f-0242-4ff6-9869-5e6dc28e5831",
  :dom/attr #:dom-attr{:key "level", :value 1}}]

Niki11:07:47

No, you can’t use leading underscore in schema at all

seepel20:07:41

Thanks for the confirmation! I did end up creating a :dom/attr-parent to handle this and it seems to be working. I'm glad to understand why my previous schema wasn't working 🙂