Support for creating/deleting relationships
Closed this issue · 1 comments
firstgeneration commented
Is there a way to use useMutation
or useClient
to achieve a relationship creation/deletion, shown below? Thank you!
POST or DELETE /articles/1/relationships/comments HTTP/1.1
{
"data": [
{ "type": "comments", "id": "123" }
]
}
aribouius commented
@firstgeneration haven't tested this, but it does look like the serializer handles arrays. Give one of these approaches a try:
function approach1() {
const [mutate] = useMutation('articles/1/relationships/comments')
const onSubmit = () => {
mutate([{ id: 123 }])
}
}
function approach2() {
const client = useClient()
const onSubmit = () => {
client.mutate('articles/1/relationships/comments', [{ id: 123 }])
}
}