asami

Jakub Holý (HolyJak) 2023-01-22T08:10:43.530589Z

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!

✅ 1
Jakub Holý (HolyJak) 2023-01-23T08:23:58.297819Z

family is always a priority 🙂 Thank you

quoll 2023-01-23T14:06:28.753469Z

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

quoll 2023-01-23T14:07:44.730839Z

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.

👍 1
quoll 2023-01-23T14:08:25.757519Z

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

👍 1
quoll 2023-01-23T14:09:23.051989Z

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

quoll 2023-01-23T14:10:16.544469Z

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

✅ 1
Jakub Holý (HolyJak) 2023-01-23T14:10:18.070329Z

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

Jakub Holý (HolyJak) 2023-01-23T14:10:47.266249Z

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

quoll 2023-01-23T14:10:55.255839Z

Yes. It's an explicit test

Jakub Holý (HolyJak) 2023-01-23T14:11:08.670859Z

I see, that makes sense.

quoll 2023-01-23T14:11:14.802339Z

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

Jakub Holý (HolyJak) 2023-01-23T14:11:31.640609Z

I see

quoll 2023-01-23T14:12:07.022879Z

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)

👍 1
Jakub Holý (HolyJak) 2023-01-23T14:12:35.677859Z

And I suppose the default is false, right?

✅ 1
quoll 2023-01-23T14:12:52.799399Z

Ummm.... I need to look 😄

Jakub Holý (HolyJak) 2023-01-23T14:13:07.608319Z

well, I can look too 🙂

Jakub Holý (HolyJak) 2023-01-23T14:14:04.315739Z

yup, false it is

quoll 2023-01-23T14:14:16.166619Z

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) 2023-01-23T14:14:21.835349Z

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

👍 1
Jakub Holý (HolyJak) 2023-01-23T14:15:00.684629Z

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) 2023-01-23T14:15:12.724119Z

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

quoll 2023-01-23T14:20:49.439889Z

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

quoll 2023-01-23T14:21:06.512309Z

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

Jakub Holý (HolyJak) 2023-01-23T14:32:13.271259Z

Awesome! Thanks!

quoll 2023-01-22T10:05:10.464959Z

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) 2023-01-22T12:09:00.717019Z

No hurry! Please do take care of yourself!

quoll 2023-01-23T03:39:49.819529Z

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

quoll 2023-01-25T19:33:32.915809Z

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 https://github.com/quoll/asami/wiki/7.-Asami-API#entity

🙌 1
quoll 2023-01-25T19:34:23.840759Z

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

Jakub Holý (HolyJak) 2023-01-25T21:31:25.048079Z

Great! Thank you!