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"]}@quoll 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
Hey there. Sorry I’ve been incommunicado. I was away at a conference all last week, and before that I was prepping for ClojureD
Do you want to DM me?