Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for creating/deleting relationships #23

Closed
firstgeneration opened this issue Oct 17, 2020 · 1 comment
Closed

Support for creating/deleting relationships #23

firstgeneration opened this issue Oct 17, 2020 · 1 comment

Comments

@firstgeneration
Copy link

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
Copy link
Owner

@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 }])
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants