guidance for payload.update() when updating Relationship field #204
-
Hi Payload team. I haven't been able to find substantial documentation for payload.update() when the updated field is
The gist: I have a parent-child relationship between items of various collections (mixed-content tree). I want to re-parent the updated item by removing the child from the old parent's I have a hook set up to do this, but I cannot for the life of me figure out what the call to If I manually add entries to the
I would expect I can update this list by removing an item from the array or appending another object with the form
however this will not save.
The error provided
makes it seem like Payload is expecting to receive data in the format
however this is cursed. It doesn't work either and causes new craziness that encouraged me to drop the collection in Mongo and start fresh. It would be great if you could point me to documentation for updating If there isn't documentation but you're willing to explain it I would be happy to put in a PR for a documentation update. TYSM |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 15 replies
-
I feel you should look into hooks as quick advice. At least that's how I created something similar. |
Beta Was this translation helpful? Give feedback.
-
Hey @RobertAlbus — I can shine some light on this for you! First up, from your question above, this snippet is an example for how a [
{
relationTo: 'pages',
value: {
parent: [Object],
title: 'Sub Page',
renderings: [],
children: [],
createdAt: '2021-06-20T06:05:13.529Z',
updatedAt: '2021-06-22T00:57:55.799Z',
id: '60ceda99361a3300191cfd7b'
}
}
] However, the actual data that is stored in the database looks like this: [
{
relationTo: 'pages',
value: ObjectID('60ceda99361a3300191cfd7b'),
}
] So, to update, you need to send it data just like you mentioned: [
...
{
relationTo: 'datasource-folders',
value: '60ceda71361a3300191caa12'
},
] What is the error that is displaying when you try to |
Beta Was this translation helpful? Give feedback.
I feel you should look into hooks as quick advice. At least that's how I created something similar.