Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Adding Sub-Fields to Group Columns in Collections

default discord avatar
zed0547last year
12

Hey

@210364152571494400



What about a top-level field called

dataName

that is populated in a beforeChange?

  • default discord avatar
    namago01last year

    I think this wasn't something to report, the thing is that in the afterRead for the

    virtualTitle

    as we are doing a

    select

    for only this field, the rest of the fields are obviously not being fetched, then when using the

    siblingData

    it was undefined/null.



    I fixed this by doing a check in the

    afterRead

    — if the

    website.data.name

    is 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

    useAsTitle

    of the collections, I found this very old discussion where the same thing is discussed:


    https://payloadcms.com/community-help/discord/useastitle-a-field-not-id-from-a-relationship

    I'd love to investigate this and issue a PR if you guys thing it's fine

  • default discord avatar
    zed0547last year

    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

    everywhere

    the doc is being read

  • default discord avatar
    namago01last year

    what other thing would you use here? I'd like to avoid duplicated data in the db

  • default discord avatar
    zed0547last year

    API, Admin, everywhere



    beforeChange

  • default discord avatar
    namago01last year

    thats true...

  • default discord avatar
    zed0547last year

    It occurs

    once

    Only on saving the data



    Just mark the field as not-virtual, an ordinary field, and save it in advance

  • default discord avatar
    namago01last year

    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

    afterRead

    trigger...)

  • default discord avatar
    zed0547last year

    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

  • default discord avatar
    namago01last year

    yeah that souunds like a good idea, thanks!



    what do you thin about the other topic? and about sending a PR?

  • default discord avatar
    zed0547last year

    I think that would make for a nice improvement!

  • default discord avatar
    namago01last year

    😎 thank you man



    as always

  • default discord avatar
    zed0547last year

    My pleasure, as always!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.