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

How to include a relationship while sending a request? #418

Closed
gadelkareem opened this issue May 21, 2020 · 4 comments
Closed

How to include a relationship while sending a request? #418

gadelkareem opened this issue May 21, 2020 · 4 comments

Comments

@gadelkareem
Copy link

It looks like the only place the relations are used in the GET request. Any way to send a POST|PATCH request while including a relationship?

@wopian
Copy link
Owner

wopian commented May 21, 2020

The first example here has targetUser and user relationships in PATCH. Same applies with POST

https://github.com/wopian/kitsu/tree/master/packages/kitsu#examples-6

api.create('posts', {
  content: 'Hello World',
  targetUser: {
    id: '42603',
    type: 'users'
  },
  user: {
    id: '42603',
    type: 'users'
  }
})

@gadelkareem
Copy link
Author

You are right, I was missing the id thanks!

@gadelkareem
Copy link
Author

gadelkareem commented May 21, 2020

It seems that including an array of objects as a relationship, results in removing all the attributes of each object except the ID, ex:

api.create('posts', {
      content: 'Hello World',
      users: [{
        id: '1',
        test: 'test1',
        type: 'users'
      },
      {
        id: '2',
        test: 'test2',
        type: 'users'
      }]
    })

Result

{
  "data": {
    "type": "posts",
    "attributes": {
      "content": "Hello World"
    },
    "relationships": {
      "users": {
        "data": [
          {
            "id": "1",
            "type": "users"
          },
          {
            "id": "2",
            "type": "users"
          }
        ]
      }
    }
  }
}

@gadelkareem gadelkareem reopened this May 21, 2020
@wopian wopian closed this as completed in ddcc17a May 21, 2020
@wopian
Copy link
Owner

wopian commented May 21, 2020

Fixed 9.0.x regression in 9.1.5.

@wopian wopian reopened this May 21, 2020
@wopian wopian closed this as completed May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants