Like what we’re doing? Star us on GitHub!

adding child when adding parent

MattRvt
9 months ago
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

  • jmikrut
    Payload Team
    9 months ago

    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
  • MattRvt
    9 months ago

    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 🥳

  • jmikrut
    Payload Team
    9 months ago

    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
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More