Skip to content

Commit 98600a6

Browse files
committed
Fixed issue when string values were interpreted as lookup refs (closes #214)
1 parent cb50be9 commit 98600a6

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fixed infinite loop in parser on CLJS 1.9.456+ (#210)
44
- Added `contains?` to built-ins (#211)
55
- Fixed handling of false values in entity cache (PR #198, thx [Brandon Bloom](https://github.com/brandonbloom))
6+
- Fixed issue when string values were interpreted as lookup refs (#214)
67

78
# 0.15.5
89

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
:1.9 { :dependencies [[org.clojure/clojure "1.9.0-alpha15" :scope "provided"]
7777
[org.clojure/clojurescript "1.9.494" :scope "provided"]]
7878
:global-vars { *print-namespace-maps* false } }
79-
:dev { :source-paths ["bench/src" "test" "dev"] }
79+
:dev { :source-paths ["bench/src" "test" "dev"]
80+
:dependencies [[org.clojure/tools.nrepl "0.2.12"]] }
8081
}
8182

8283
:clean-targets ^{:protect false} [

src/datascript/query.cljc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,12 @@
302302
(if (and (not (nil? *lookup-attrs*))
303303
(contains? *lookup-attrs* attr))
304304
(fn [tuple]
305-
(let [eid (#?(:cljs aget :clj get) tuple idx)]
306-
(if (number? eid) ;; quick path to avoid fn call
307-
eid
308-
(db/entid *lookup-source* eid))))
305+
(let [eid (#?(:cljs aget :clj get) tuple idx)]
306+
(cond
307+
(number? eid) eid ;; quick path to avoid fn call
308+
(sequential? eid) (db/entid *lookup-source* eid)
309+
(da/array? eid) (db/entid *lookup-source* eid)
310+
:else eid)))
309311
(fn [tuple]
310312
(#?(:cljs aget :clj get) tuple idx)))))
311313

test/datascript/test/lookup_refs.cljc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@
233233
[[:name "Ivan"] [:name "Petr"] [:name "Oleg"]])
234234
#{[[:name "Ivan"] [:name "Petr"]]
235235
[[:name "Petr"] [:name "Oleg"]]}))
236+
237+
;; https://github.com/tonsky/datascript/issues/214
238+
(is (= (d/q '[:find ?e
239+
:in $ [?e ...]
240+
:where [?e :friend 3]]
241+
db [1 2 3 "A"])
242+
#{[2]}))
236243

237244
(let [db2 (d/db-with (d/empty-db schema)
238245
[{:db/id 3 :name "Ivan" :id 3}

0 commit comments

Comments
 (0)