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.


  • Selected Answer
    discord user avatar
    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


Chat on Discord



Can't find what you're looking for?

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