Skip to content

Support array data for updating to-many relationships #56

@nikajukic

Description

@nikajukic

I've noticed that array data in a request body isn't supported and it's actually a part of the JSON:API specification.

https://jsonapi.org/format/#crud-updating-to-many-relationships

Example body:

PATCH /articles/1/relationships/tags HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": [
    { "type": "tags", "id": "2" },
    { "type": "tags", "id": "3" }
  ]
}
params

:data=>[{:id=>"2", :type=>"tags"}, {:id=>"3", :type=>"tags"}]

It currently breaks with when I call params.from_jsonapi with

TypeError: no implicit conversion of Symbol into Integer
...lib/jsonapi_parameters/translator.rb:37:in `dig`

I would expect it to be parsed to:

tag_ids: [2, 3]

Thank you for this gem! 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions