jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
319 stars 63 forks source link

Deleting Relationships #73

Closed ajunB7 closed 2 years ago

ajunB7 commented 6 years ago

According to the spec: http://jsonapi.org/format/#crud-updating-relationships

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

{
  "data": null
}

is a valid request. However, I'm seeing the following error: The request MUST include a single resource object as primary data.

beauby commented 6 years ago

@ajuni7 Thanks for the issue. At the moment there is little tooling in jsonapi-rails to handle relationship endpoints. You should get by by not using deserializable_resource and instead manually dealing with params[:_jsonapi]. This is not ideal, but it's the current situation.

ajunB7 commented 6 years ago

Thanks for the quick response @beauby. I was wondering, in Rails is there a way to manually call the Deserializer on a hash?

For the case where the data isn't null, this workaround would be feasible given we can manually call the deserializer when needed.

Edit: I found out that its possible to do so with

JSONAPI::Rails::DeserializableResource.new(json_api_params).to_h
beauby commented 6 years ago

@ajuni7 I updated your comment, but yeah you got the idea.