Fork me on GitHub
#datascript
<
2019-01-11
>
fenton20:01:55

Why do lookup-refs not work as in the following:

(def conn1 (make-db
              [{:name {:db/unique :db.unique/identity}}]
              [{:name "Bob"}]))
  (d/entity (d/db conn1) [:name "Bob"])

fenton20:01:18

#error {:message "Lookup ref attribute should be marked as :db/unique: [:name \"Bob\"]", :data {:error :lookup-ref/unique, :entity-id [:name "Bob"]}}

fenton20:01:06

(defn make-db [schema data]
  (let [conn (d/create-conn)]
    (d/transact! conn (concat schema data))
    conn))

metasoarous20:01:47

@fenton - The schema should not be [{:name {...}}], just rather just {:name {...}}.

fenton20:01:31

...and should be in the (/d/create-conn) as opposed to in a (d/transact! conn ... too...

metasoarous20:01:27

Datascript does not have dynamic schema

fenton20:01:30

got it, confused by docs on this...

metasoarous20:01:36

It's fixed at db/conn value creation

fenton20:01:44

okay cool, phew! 🙂

metasoarous20:01:46

In Datomic, the schema is live, and you update it by submitting transactions, so it's entirely possible you were lead to believe you could do this by having seen some Datomic documentation/code

fenton20:01:36

yeah...for sure... i guess datascript documentation is a bit fragmented...