Fork me on GitHub
#datascript
<
2020-08-19
>
Andrew14:08:14

I guess you need [(< 0 ?p)] to express a predicate, right now datascript thinks it's a rule expression. https://docs.datomic.com/on-prem/query.html#expression-clauses

oly15:08:13

wondering if some one can help I am playing with datascript and the a bit confused on :db/ref if i query some thing that has a ref I get it returned as #:db{:id 1} can that not auro resolve back the attributes ?

oly15:08:30

(def schema {:type/id     {:db/unique :db.unique/identity}
             :product/id {:db/unique :db.unique/identity}
             :product/type {:db/valueType :db.type/ref}})

(def conn (d/create-conn schema))

(d/transact!
 conn
 [{:type/id 1 :type/name "type 1"}
  {:type/id 2 :type/name "type 2"}
  {:product/id 1 :product/name "p1" :product/type [:type/id 1]}
  {:product/id 2 :product/name "p2" :product/type [:type/id 2]}])

(d/q '[:find  (pull ?e [*])
       :where
       [?e :product/id]] @conn)

oly15:08:02

That's my simple example which returns

0. [ { :db/id 4, :product/id 1, :product/name "p1", :product/type { :db/id 1 } } ]

oly15:08:54

I am wondering if I can make it return :type/name in the row and other type related attributes instead of :product/type {:db/id 1}

oly15:08:32

feel free to point me at docs, could be I have just been missing or mis understanding how it works

lilactown16:08:00

@oliver.marks I believe * only gets all of the attributes one level deep. you could try playing around with something like:

(d/q '[:find (pull ?e [* {:product/type [*]}])
       :where
       [?e :product/id]] @conn)

lilactown16:08:08

(I haven’t tried that)

lilactown16:08:15

(I’m also not very good at datalog)

oly16:08:32

@lilactown spot on that's works perfectly 🙂