Wikodit / js-data-jsonapi-light

JSData adapter which serialize and deserialize JSONApi response and requests.
MIT License
8 stars 4 forks source link

Add an option to send relationships within the attributes structure #23

Closed Tronix117 closed 7 years ago

Tronix117 commented 7 years ago

That is just for convenience since it is not a specification of JsonAPI, however it can be useful with some specific backends.

The idea is to give an forceRelationshipsInAttributes: true option to the save or the update.

Without the option:

PATCH /articles
{
  "data": {
    "type: "Article",
    "id": "xxx-xxx-xxx",
    "attributes": {
      "title": "New title"
    },
    "relationships": {
      "author": {
        "data": {
          "type": "User",
          "id": "yyy-yyy-yyy"
        }
      }
    }
  }
}

With the option:

PATCH /articles
{
  "data": {
    "type: "Article",
    "id": "xxx-xxx-xxx",
    "attributes": {
      "title": "New title",
      "authorId": "yyy-yyy-yyy"
    }
  }
}

Ref #21, it has been evoked in the comments