adding child when adding parent

default discord avatar
MattRvt
last year
1 1

Is this possible to add children when receiving post request with this kind of content:
http://localhost:3000/api/parent?depth=1

{
    "name": "parent",
    "child":{
        "name": "child"
    }
}

This would create child and parent object. Instead, I get child: null in the answer

  • discord user avatar
    jmikrut
    Payload Team
    last year

    Hey @MattRvt — right now, this is not possible. It could be a a future feature that we build, but it'll take some new functionality to achieve. The way we'd do this currently is to first create the nested document, then pass the newly created document's ID to your parent doc.

    So:

    const parentDocData = {
        "name": "parent",
        "child": "6a3434543qw3derra" // ID of newly created child doc
    }
    2 replies
  • default discord avatar
    MattRvt
    last year

    Thank you for your reply. This feature would be awesome.

    The same way, being able to create child through the UI from the parent page as it is done with array would be a great feature.

    Again, many thanks for your work, your reply and the great documentation 🥳

  • discord user avatar
    jmikrut
    Payload Team
    last year

    You got it!

    Actually we are definitely going to allow creating a child through the UI from the parent page. That's on the radar. Stay tuned!

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.