Skip to content

Conversation

@JaZo
Copy link
Contributor

@JaZo JaZo commented Jun 21, 2022

This allows you to remove a to-one relationship by sending null in a PATCH request, as described in the spec.

Request

PATCH {{baseUrl}}/model/:model/relationships/related

{
  "data": null
}

Result

Before

{
    "jsonapi": {
        "version": "1.0"
    },
    "errors": [
        {
            "detail": "Expecting JSON API specification compliance to have been run.",
            "meta": {
                "exception": "LogicException",
                "file": "vendor/laravel-json-api/laravel/src/Http/Requests/ResourceRequest.php",
                "line": 209,
                "trace": []
            },
            "status": "500",
            "title": "Internal Server Error"
        }
    ]
}

After

{
    "jsonapi": {
        "version": "1.0"
    },
    "links": {
        "related": "{{baseUrl}}/model/1/related",
        "self": "{{baseUrl}}/model/1/relationships/related"
    },
    "data": null
}

This allows you to remove a to-one relationship by sending `null` in a PATCH request.
@JaZo JaZo changed the title Allow null as data Allow null as data in relationship PATCH request Jun 21, 2022
@lindyhopchris
Copy link
Contributor

@JaZo thanks for submitting the PR, can't believe no one has encountered this error before now!

@lindyhopchris lindyhopchris merged commit 74cd6e5 into laravel-json-api:develop Jun 25, 2022
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

Successfully merging this pull request may close these issues.

2 participants