Fork me on GitHub
Jakub Holý (HolyJak)08:01:43

I am confused: why is the whole sub-entity address returned, even though I explicitly requested nested? false? The code:

@(d/transact conn {:tx-data [{:id               [:person/id "ann"]
                              :person/id        "ann"
                              :person/addresses [{:address/id     "a-one"
                                                  :address/street "First St."}]}]})
(d/entity conn [:person/id "ann"] false)
; =>
{:id [:person/id "ann"], :person/id "ann",
 :person/addresses [#:address{:id "a-one", :street "First St."}]}
I.e. I expected to get back just ... :person/addresses [#:address{:id "a-one"}] , i.e. w/o the :street . Thank you!


Hmmm, I would have expected that too. It’s still 5am here and I shouldn’t be up for a few hours yet (just looked at my phone because I couldn’t sleep). Let me check this out and get back to you.

Jakub Holý (HolyJak)12:01:00

No hurry! Please do take care of yourself!


Well… family ended up taking priority today, which was not the schedule I expected. But this has been on my mind all day. I want to get to it as soon as I can

Jakub Holý (HolyJak)08:01:58

family is always a priority 🙂 Thank you


Ah... I see what it is. The problem is twofold: • improper documentation • me not having worked in that area of the code for too long, and being forgetful


There are entities that are considered "top level entities" and others that are nested. Any entity that you transact will be marked as "top level". Anything nested inside of it won't be.

👍 2

What's the difference? Top level entities will always have an ID assigned to them, and they will always have a property of :a/entity true

👍 2

You can reference a top level entity inside another entity, which is really useful for declaring them separately, or if multiple entities refer to them, or if you want a loop of some type


However, when you reference an entity this way, you might just want to see the reference to the entity, and not see the entire thing nested inside

Jakub Holý (HolyJak)14:01:18

I see I did not include :id on the nested entities here, which is not what I intended to do 😅

Jakub Holý (HolyJak)14:01:47

Ah, so nested? works only for referenced top entities?


Yes. It's an explicit test

Jakub Holý (HolyJak)14:01:08

I see, that makes sense.


The idea is that if you nest a structure, then it's an implicit part of it's parent. You will always see it


But if an entity references an existing entity, then it's like a foreign address. You can nest it if you want (set the nested? property to true) or you can just see the reference (`nested?` set to false)

👍 2
Jakub Holý (HolyJak)14:01:35

And I suppose the default is false, right?


Ummm.... I need to look 😄

Jakub Holý (HolyJak)14:01:07

well, I can look too 🙂


First of all though, I haven't typed this in (yet), but you should be able to say something like this...

(d/transact conn {:tx-data [{:id "a-one"
                             :address/id     "a-one"
                             :address/street "First St."}
                            {:id               [:person/id "ann"]
                             :person/id        "ann"
                             :person/addresses [{:id "a-one"}]}]})

Jakub Holý (HolyJak)14:01:21

I mean, my statement is true and the value is false 😅

👍 2
Jakub Holý (HolyJak)14:01:00

Thank you, that is exactly what I need. I will try that and get back to you if it does not work.

Jakub Holý (HolyJak)14:01:12

Thank you very much for your help and insights, most appreciated!


PS. I initially messed up the closing parens on that example, but I've fixed it now


Also, I just checked if my suggestion worked, and it does


I updated the docs around entity. This was needed, because it turned out that it had gone stale. The previous version: • Did not mention the nested? argument • Incorrectly stated that references to top-level entities would be returned as nil

🙌 2

I mean... that's how it used to work, but the docs were not updated as the function changed