Hey
@210364152571494400
What about a top-level field called
dataNamethat is populated in a beforeChange?
I think this wasn't something to report, the thing is that in the afterRead for the
virtualTitleas we are doing a
selectfor only this field, the rest of the fields are obviously not being fetched, then when using the
siblingDatait was undefined/null.
I fixed this by doing a check in the
afterRead— if the
website.data.nameis present use that, if not, query the DB for the name of that field
I do still think that there should be a way to use a nested field as the title in the
useAsTitleof the collections, I found this very old discussion where the same thing is discussed:
I'd love to investigate this and issue a PR if you guys thing it's fine
afterRead's are honestly not ideal here I think
I use afterRead hooks sparingly when there are no other possible options
The issue is this hook triggers
everywherethe doc is being read
what other thing would you use here? I'd like to avoid duplicated data in the db
API, Admin, everywhere
beforeChange
thats true...
It occurs
onceOnly on saving the data
Just mark the field as not-virtual, an ordinary field, and save it in advance
So your idea is to save the nested title inside this top-level field? meaning I would essentially have the same thing saved in two different fields? (which now that I come to think about it, might even be better than querying the database on every
afterReadtrigger...)
Right
In this way we reduce likely/potentially an enormous amount of fetching that needs to happen and extra processing that needs to run on every read
yeah that souunds like a good idea, thanks!
what do you thin about the other topic? and about sending a PR?
I think that would make for a nice improvement!
😎 thank you man
as always
My pleasure, as always!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.