Skip to content

Commit

Permalink
Fixed issue when string values were interpreted as lookup refs (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Apr 9, 2017
1 parent cb50be9 commit 98600a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fixed infinite loop in parser on CLJS 1.9.456+ (#210)
- Added `contains?` to built-ins (#211)
- Fixed handling of false values in entity cache (PR #198, thx [Brandon Bloom](https://github.com/brandonbloom))
- Fixed issue when string values were interpreted as lookup refs (#214)

# 0.15.5

Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
:1.9 { :dependencies [[org.clojure/clojure "1.9.0-alpha15" :scope "provided"]
[org.clojure/clojurescript "1.9.494" :scope "provided"]]
:global-vars { *print-namespace-maps* false } }
:dev { :source-paths ["bench/src" "test" "dev"] }
:dev { :source-paths ["bench/src" "test" "dev"]
:dependencies [[org.clojure/tools.nrepl "0.2.12"]] }
}

:clean-targets ^{:protect false} [
Expand Down
10 changes: 6 additions & 4 deletions src/datascript/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,12 @@
(if (and (not (nil? *lookup-attrs*))
(contains? *lookup-attrs* attr))
(fn [tuple]
(let [eid (#?(:cljs aget :clj get) tuple idx)]
(if (number? eid) ;; quick path to avoid fn call
eid
(db/entid *lookup-source* eid))))
(let [eid (#?(:cljs aget :clj get) tuple idx)]
(cond
(number? eid) eid ;; quick path to avoid fn call
(sequential? eid) (db/entid *lookup-source* eid)
(da/array? eid) (db/entid *lookup-source* eid)
:else eid)))
(fn [tuple]
(#?(:cljs aget :clj get) tuple idx)))))

Expand Down
7 changes: 7 additions & 0 deletions test/datascript/test/lookup_refs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@
[[:name "Ivan"] [:name "Petr"] [:name "Oleg"]])
#{[[:name "Ivan"] [:name "Petr"]]
[[:name "Petr"] [:name "Oleg"]]}))

;; https://github.com/tonsky/datascript/issues/214
(is (= (d/q '[:find ?e
:in $ [?e ...]
:where [?e :friend 3]]
db [1 2 3 "A"])
#{[2]}))

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

0 comments on commit 98600a6

Please sign in to comment.