This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-11
Channels
- # announcements (3)
- # asami (4)
- # babashka (79)
- # babashka-sci-dev (47)
- # beginners (97)
- # biff (12)
- # calva (7)
- # clj-commons (3)
- # clj-kondo (22)
- # clj-on-windows (13)
- # cljdoc (31)
- # cljfx (2)
- # cljs-dev (1)
- # clojure (85)
- # clojure-austin (4)
- # clojure-dev (12)
- # clojure-europe (15)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-uk (4)
- # community-development (19)
- # conjure (3)
- # core-typed (40)
- # cursive (9)
- # datahike (21)
- # datomic (1)
- # emacs (7)
- # exercism (2)
- # graalvm (20)
- # graphql (1)
- # honeysql (16)
- # jobs (1)
- # malli (2)
- # off-topic (3)
- # pathom (28)
- # pedestal (3)
- # polylith (7)
- # reitit (14)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (4)
- # shadow-cljs (21)
- # sql (21)
- # testing (8)
- # tools-deps (23)
- # vscode (8)
- # xtdb (38)
It seems that :db/add supports lookup node-refs in the subject position for existing entities, as the following test passes:
(deftest existing-add-ref
@(d/transact *conn* {:tx-data [{:id "existing1"}
{:id "existing2"}]})
@(d/transact *conn* {:tx-data [[:db/add [:id "existing1"] :ref [:id "existing2"]]]})
(is (= {:id "existing1",
:ref {:id "existing2"}}
(d/entity (d/db *conn*) "existing1"))))
I struggle to understand what is the correct way to 1. create a new entity and 2. link an existing entity to it. For the link I cannot use the new entity's :id
as a lookup ref because it is not created yet and I do not have any other ID (since I cannot use :db/id -1
together with specifying a custom :id
). It is demonstrated by the following failing test:
(deftest existing-add-ref-to-new
@(d/transact *conn* {:tx-data [{:id "existing"}]})
@(d/transact *conn* {:tx-data [{:id "new"}
[:db/add [:id "existing"] :ref [:id "new"]]]})
; BROKEN: Resolving the lookup ref does not work, it is stored as-is - likely b/c the entity cannot be looked up
; since we are only just creating it
(is (= {:id "existing",
:ref {:id "new"}}
(d/entity (d/db *conn*) "existing"))))
; => Expected {... :ref {:id "new"}}, Actual {... :ref [:id "new"]}
@U051N6TTC I'd like to help fix ☝️, ie make it possible to include new entities being added by the current transaction in where we look up the :id IDs. Any pointers, ideas? (I guess entities/resolve-lookup-refs
is the place to look. The code is very readable, great job!)
I see Issues are still not enabled so I https://github.com/quoll/asami/pull/2 instead