How to create an item and connect other documents to relationship field inside #12594
-
|
Hi! Imagine I have some kind of entity (post), which have a relation to another entity (tags, const newPost = await req.payload.create({
collection: 'posts',
data: {
tags: [{ connect: { id: { equals: 5 } } }],
}
})I didn't found even single example about how to use Payload local API with relationship data. Would really appreciate if someone will help there. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hey @MinskLeo Right, this is definitely a common use case but the answer is much simpler than that. If you have the id's of the tag documents you want to create a relationship to, then it would be: const newPost = await req.payload.create({
collection: 'posts',
data: {
//... other fields
tags: [tagOne.id, tagTwo.id, tagThree.id],
}
})You simply pass the ID's of the tags. |
Beta Was this translation helpful? Give feedback.
Hey @MinskLeo
Right, this is definitely a common use case but the answer is much simpler than that. If you have the id's of the tag documents you want to create a relationship to, then it would be:
You simply pass the ID's of the tags.