Fork me on GitHub
#datascript
<
2019-02-16
>
mattly19:02:42

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

mattly19:02:06

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

mattly19:02:42

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

mattly19:02:03

I've tried

mattly19:02:39

[: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

dpsutton19:02:12

(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"}]}  

dpsutton19:02:15

sorry to overuse thing so much lol

mattly19:02:24

eh it gets the idea across

mattly19:02:52

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