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.

How to associate parent to children so children has the id of parent?

default discord avatar
alexisbrouillettelast year
1 1

Hi! I'm trying to create a relation between a Task and a Step. I got the part where the Task has a relationTo Step, but i cannot find how to give the step collection the id of the parent(the task associated) I've tried using collection hooks, but the object is partial and i only got the id of the step, not the actual object : steps: [ { value: '639b487524769b06297d5b25', relationTo: 'steps' } ],.

I want to know it the collection hooks is the way to go and how i would access the step object from the hook in the task collection or if there is a better way to do this.

Thanks!

  • Selected Answer
    discord user avatar
    JarrodMFlesch
    last year

    You will need to perform a payload.findByID (see here) operation to look up the entire step document.

    // Note: there will be a more eloquent way to do this, since you will likely want to loop and get all steps?
    const fullDoc = await payload.findByID({ collection: 'steps', id: step[0].value });
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..