Skip to content

Commit

Permalink
Fixed js query lookup ref test #462
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Apr 23, 2024
1 parent 2f72892 commit 8e1abae
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/datascript/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@
(or (keyword? form) (string? form)))

(defn lookup-ref? [form]
(looks-like? [attr? '_] form))
(and
(or (sequential? form) (da/array? form))
(= 2 (count form))
(attr? (first form))))

;; Relation algebra

Expand Down Expand Up @@ -666,13 +669,17 @@

(defn resolve-pattern-lookup-refs [source pattern]
(if (satisfies? db/IDB source)
(let [[e a v tx] pattern]
(->
[(if (or (lookup-ref? e) (attr? e)) (db/entid-strict source e) e)
a
(if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v))) (db/entid-strict source v) v)
(if (lookup-ref? tx) (db/entid-strict source tx) tx)]
(subvec 0 (count pattern))))
(let [[e a v tx] pattern
e' (if (or (lookup-ref? e) (attr? e))
(db/entid-strict source e)
e)
v' (if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v)))
(db/entid-strict source v)
v)
tx' (if (lookup-ref? tx)
(db/entid-strict source tx)
tx)]
(subvec [e' a v' tx'] 0 (count pattern)))
pattern))

(defn dynamic-lookup-attrs [source pattern]
Expand Down

0 comments on commit 8e1abae

Please sign in to comment.