Skip to content

Commit 8e1abae

Browse files
committed
Fixed js query lookup ref test tonsky#462
1 parent 2f72892 commit 8e1abae

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/datascript/query.cljc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@
9595
(or (keyword? form) (string? form)))
9696

9797
(defn lookup-ref? [form]
98-
(looks-like? [attr? '_] form))
98+
(and
99+
(or (sequential? form) (da/array? form))
100+
(= 2 (count form))
101+
(attr? (first form))))
99102

100103
;; Relation algebra
101104

@@ -666,13 +669,17 @@
666669

667670
(defn resolve-pattern-lookup-refs [source pattern]
668671
(if (satisfies? db/IDB source)
669-
(let [[e a v tx] pattern]
670-
(->
671-
[(if (or (lookup-ref? e) (attr? e)) (db/entid-strict source e) e)
672-
a
673-
(if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v))) (db/entid-strict source v) v)
674-
(if (lookup-ref? tx) (db/entid-strict source tx) tx)]
675-
(subvec 0 (count pattern))))
672+
(let [[e a v tx] pattern
673+
e' (if (or (lookup-ref? e) (attr? e))
674+
(db/entid-strict source e)
675+
e)
676+
v' (if (and v (attr? a) (db/ref? source a) (or (lookup-ref? v) (attr? v)))
677+
(db/entid-strict source v)
678+
v)
679+
tx' (if (lookup-ref? tx)
680+
(db/entid-strict source tx)
681+
tx)]
682+
(subvec [e' a v' tx'] 0 (count pattern)))
676683
pattern))
677684

678685
(defn dynamic-lookup-attrs [source pattern]

0 commit comments

Comments
 (0)