Skip to content

Clarify relationship formatting #480

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

Merged
merged 7 commits into from
Mar 26, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply same logic to PATCH
  • Loading branch information
Ethan authored and Ethan committed Mar 21, 2015
commit f17d17fdcfa447693673d8ef3a47c1fc1dc8c9e6
35 changes: 14 additions & 21 deletions format/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,11 @@ Accept: application/vnd.api+json
}
```

#### Updating a Resource's To-One Relationships <a href="#crud-updating-resource-to-one-relationships" id="crud-updating-resource-to-one-relationships" class="headerlink"></a>
#### Updating a Resource's Relationships <a href="#crud-updating-resource-relationships" id="crud-updating-resource-relationships" class="headerlink"></a>

If a to-one relationship is provided in the `links` section of a resource
object in a `PATCH` request, its value **MUST** be either:

* an object with `type` and `id` members corresponding to the related resource
* `null`, to remove the relationship
If a relationship is provided in the `links` section of a resource object in a
`PATCH` request, its value **MUST** be a link object with a `linkage` member.
The relationship's value will be replaced with the value specified in this member.

For instance, the following `PATCH` request will update the `title` attribute
and `author` relationship of an article:
Expand All @@ -1096,22 +1094,15 @@ Accept: application/vnd.api+json
"id": "1",
"title": "Rails is a Melting Pot",
"links": {
"author": { "type": "people", "id": "1" }
"author": {
"linkage": { "type": "people", "id": "1" }
}
}
}
}
```

#### Updating a Resource's To-Many Relationships <a href="#crud-updating-resource-to-many-relationships" id="crud-updating-resource-to-many-relationships" class="headerlink"></a>

If a to-many relationship is included in the `links` section of a resource
object, it **MUST** be either:

* an array of objects each containing `type` and `id` members to replace all
members of the relationship.
* an empty array (`[]`) to clear the relationship.

For instance, the following `PATCH` request performs a complete replacement of
Likewise, the following `PATCH` request performs a complete replacement of
the `tags` for an article:

```text
Expand All @@ -1125,10 +1116,12 @@ Accept: application/vnd.api+json
"id": "1",
"title": "Rails is a Melting Pot",
"links": {
"tags": [
{ "type": "tags", "id": "2" },
{ "type": "tags", "id": "3" }
]
"tags": {
"linkage": [
{ "type": "tags", "id": "2" },
{ "type": "tags", "id": "3" }
]
}
}
}
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy