Brandon Bloom
2017-08-07 21:43:22 UTC
I noticed some strange behavior (maybe a bug?) at the intersection of
entity ref attributes and :db/ident
The problem is that ref attributes (both cardinality one and many) don't
produce entity objects if the entity has a :db/ident attribute attached. In
that case, the ident itself is returned as a keyword.
For example:
(deref (d/transact conn [{:db/ident :foo/ref
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]))
(deref (d/transact conn [[:db/add "x" :db/ident :thing]]))
(let [y (-> @(d/transact conn [[:db/add "y" :foo/ref :thing]])
(get-in [:tempids "y"]))]
(-> (d/db conn) (d/entity y) d/touch :foo/ref)) ;=> :thing
This took me by surprise while doing some generic traversals of entities.
Luckily, d/entity-db exists. Combined with the expected behavior of
d/entity, you can work around this problem:
(d/entity (d/entity-db e) :db/doc) ;=> #:db{:id 62}
Is this a bug? If not, is the behavior documented somewhere?
Thanks,
Brandon
entity ref attributes and :db/ident
The problem is that ref attributes (both cardinality one and many) don't
produce entity objects if the entity has a :db/ident attribute attached. In
that case, the ident itself is returned as a keyword.
For example:
(deref (d/transact conn [{:db/ident :foo/ref
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]))
(deref (d/transact conn [[:db/add "x" :db/ident :thing]]))
(let [y (-> @(d/transact conn [[:db/add "y" :foo/ref :thing]])
(get-in [:tempids "y"]))]
(-> (d/db conn) (d/entity y) d/touch :foo/ref)) ;=> :thing
This took me by surprise while doing some generic traversals of entities.
Luckily, d/entity-db exists. Combined with the expected behavior of
d/entity, you can work around this problem:
(d/entity (d/entity-db e) :db/doc) ;=> #:db{:id 62}
Is this a bug? If not, is the behavior documented somewhere?
Thanks,
Brandon
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.