This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-24
Channels
- # announcements (2)
- # babashka (31)
- # beginners (608)
- # cider (60)
- # clj-kondo (22)
- # cljsrn (28)
- # clojure (14)
- # clojure-europe (5)
- # clojure-nl (3)
- # clojure-spec (1)
- # clojure-uk (19)
- # clojurescript (38)
- # conjure (20)
- # cursive (9)
- # data-science (26)
- # datascript (4)
- # datomic (19)
- # duct (4)
- # emacs (8)
- # figwheel-main (5)
- # fulcro (7)
- # helix (15)
- # leiningen (12)
- # malli (2)
- # off-topic (20)
- # overtone (3)
- # pathom (14)
- # pedestal (10)
- # re-frame (2)
- # reitit (13)
- # ring (13)
- # shadow-cljs (18)
- # spacemacs (8)
Hello, I'm trying to use lookup refs in a transaction, but I'm having trouble. I have the following tx-data in which I try to add a new fact: the user identified by follower-id
now follows the user identified by followed-id
(it is a Twitter-clone app):
{:db/id [:user/id follower-uuid]
:user/follow [:user/id followed-uuid]}
The schema is already in place and :user/id
is unique. I'm receiving this error message from Datomic:
#object[datomic.promise$settable_future$reify__4751
0x3be40c44
{:status :failed,
:val #error{:cause ":db.error/not-an-entity Unable to resolve entity: 956eb63e-6f30-4e94-a378-eee8ae0156cd in datom [[:user/id #uuid \"37b70f39-70cd-473d-9959-f81502621302\"] :user/follow #uuid \"956eb63e-6f30-4e94-a378-eee8ae0156cd\"]",
:data {:entity #uuid"956eb63e-6f30-4e94-a378-eee8ae0156cd",
:datom [[:user/id #uuid"37b70f39-70cd-473d-9959-f81502621302"]
:user/follow
#uuid"956eb63e-6f30-4e94-a378-eee8ae0156cd"],
:db/error :db.error/not-an-entity},
[more omitted]
The schema for :user/id
and :user/follow
are the following:
{:db/ident :user/id
:db/valueType :db.type/uuid
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db/index true}
{:db/ident :user/follow
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
Does anyone have a clue? Thank youHi @UNZQ84WJV , do both of the users exist in the database?
Yes, they do. I can correctly retrieve them.
And if I replace [:user/id followed-uuid]
with the entity id of the followed user, it works as expected.
And what if your tx data was instead
{:user/id follower-uuid
:user/follow [:user/id followed-uuid]}
I haven't tried that. I'll try it and comment here
The rationale would be: since :user/id
is unique, your suggestion would upsert the :user/follow
attribute?
Yep, and it will also upsert the follower
user as well, without the need for db/id
(unless you need a tempid for something, but it doesn't look like this example does.)
Are you sure u're using the uuid
fully and correctly? Could you post the full transaction with the value of the follower-uuid
?
I'm using the datomic-free API, but this example is running with an in-memory database ("datomic:<mem://mydb|mem://mydb>")
Sorry, I was away from my laptop, @U0CJ19XAM. It didn't work. It returns the same error as before.
@U2TLBUVRS, yes, it looks ok:
(d/transact conn [#:user{:id #uuid "956eb63e-6f30-4e94-a378-eee8ae0156cd", :follow [:user/id #uuid "37b70f39-70cd-473d-9959-f81502621302"]}])
I have other data that look similar and work. For instance:
#:like{:id uuid
:created-at created-at
:user [:user/id user-uuid]
:source-tweet [:tweet/id source-tweet-uuid]}
For the follow, I think it should be ... :follow [[:user/id ...]]
'cos ref type-> many card.., or use a set #{[:user/id ...]}
Wow, that worked! Will Datomic create a new datom of the form [follower-entity-id :user/follow new-followed-entity-id]
for each successive transaction? For instance, when first user (entity id 1) follows second user (entity id 2) it creates datom [1 :user/follow 2 tx-1 true]
and then when first user also follows third user (entity id 3), then the following occurs: [1 :user/follow 2 tx-2 false] [1 :user/follow 3 tx-2 true]
? Obviously this wouldn't be the correct result.