datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
mattly 2019-02-16T19:19:42.002800Z

I have a field in my schema defined as {:db/valueType :db.type/ref :db/cardinality :db.cardinality/many}

mattly 2019-02-16T19:20:06.003300Z

and I'm trying to construct a transaction that updates that field with unique refs

mattly 2019-02-16T19:21:42.004600Z

ugh, can't paste my example without slack trying to munge colons into emoji

mattly 2019-02-16T19:22:03.004800Z

I've tried

mattly 2019-02-16T19:23:39.006900Z

[:db/add eid :thing/tagged [:tag/name ["foo" "bar"]]] and [:db/add eid :thing/tagged [[:tag/name "foo"] [:tag/name "bar"]]] and neither seem to work

dpsutton 2019-02-16T19:23:39.007Z

ah, i see

dpsutton 2019-02-16T19:33:12.007300Z

(let [schema {:thing {:db/valueType   :db.type/ref
                        :db/cardinality :db.cardinality/many}
                :other {:db/unique :db.unique/value}}
        conn   (d/create-conn schema)]
    (d/transact! conn [{:other "thing-1"}
                       {:other "thing-2"}])
    (let [{:keys [tempids]} (d/transact! conn [{:main  "thing"
                                                :db/id "temp"}])]
      (d/transact! conn [[:db/add (get tempids "temp") :thing [:other "thing-1"]]
                         [:db/add (get tempids "temp") :thing [:other "thing-2"]]])
      (d/pull (d/db conn) [:main
                           {:thing [:other]}] (get tempids "temp"))))
;; => {:main "thing", :thing [{:other "thing-1"} {:other "thing-2"}]}  

mattly 2019-02-16T19:33:41.007500Z

aah

mattly 2019-02-16T19:33:44.007700Z

thanks

dpsutton 2019-02-16T19:33:48.007900Z

👍

dpsutton 2019-02-16T19:34:15.008200Z

sorry to overuse thing so much lol

mattly 2019-02-16T19:39:24.008500Z

eh it gets the idea across

mattly 2019-02-16T19:39:52.008900Z

I'm beginning to think this may be more trouble than it's worth for me