Cannot refer to a unique ref with a map
Use case:
- I want to be able to describe 1-to-1 relationships in my schema.
- My solution is to create unique refs in my schema.
Did:
- Added an attribute
:footo my schema with both:db/valueType :db.type/refand:db/unique db.unique/identity. - Transacted an entity associating
:footo a map (ref)
Expected:
-
:footo associated with the reference, which is unique in the db. - Refs can be unique and used in this way in Datomic.
Happened:
- Error:
#error {:message "Expected number or lookup ref for entity id, got {:db/id 1}", :data {:error :entity-id/syntax, :entity-id {:db/id 1}}}
Code to repro:
(require '[datascript.core :as d])
(def conn (d/create-conn {:foo {:db/valueType :db.type/ref
:db/unique :db.unique/identity}}))
(d/transact conn [{:db/id 1}{:foo 1}]) ;; OK, when referencing with a number
(def conn (d/create-conn {:foo {:db/valueType :db.type/ref
:db/unique :db.unique/identity}}))
(d/transact conn [{:db/id 1}{:foo {:db/id 1}}]) ;; throws, when using a map
Problem here is that DataScript does not understand ref when specified in a form of a map.
Datomic seems to allow using such maps in certain cases, so I’ll have to investigate and let DataScript do the same.
Until then, just use {:foo 1} instead.
On Sun, Mar 20, 2016 at 7:45 PM Petter Eriksson [email protected] wrote:
Use case:
- I want to be able to describe 1-to-1 relationships in my schema.
- My solution is to create unique refs in my schema.
Did:
- Added an attribute :foo to my schema with both :db/valueType :db.type/ref and :db/unique db.unique/identity.
- Transacted an entity associating :foo to a map (ref)
Expected:
- :foo to associated with the reference, which is unique in the db.
- Refs can be unique and used in this way in Datomic.
Happened:
- Error: #error {:message "Expected number or lookup ref for entity id, got {:db/id 1}", :data {:error :entity-id/syntax, :entity-id {:db/id 1}}}
Code to repro:
(require '[datascript.core :as d])
(def conn (d/create-conn {:foo {:db/valueType :db.type/ref :db/unique :db.unique/identity}})) (d/transact conn [{:db/id 1}{:foo {:db/id 1}}]) ;; throws
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/tonsky/datascript/issues/147