Skip to content

Commit 97cec75

Browse files
committed
Documented the new relation format option
1 parent eeab460 commit 97cec75

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

docs/usage.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If you set the `resource_name` property on the object to `False` the data
5555
will be returned without modification.
5656

5757

58-
### Inflecting object keys
58+
### Inflecting object and relation keys
5959

6060
This package includes the ability (off by default) to automatically convert json
6161
requests and responses from the python/rest_framework's preferred underscore to
@@ -120,6 +120,60 @@ Example - With format conversion set to `dasherize`:
120120
}
121121
```
122122

123+
#### Relationship types
124+
125+
A similar option to JSON\_API\_FORMAT\_KEYS can be set for the relationship names:
126+
127+
``` python
128+
JSON_API_FORMAT_RELATION_KEYS = 'dasherize'
129+
```
130+
131+
Example without format conversion:
132+
133+
``` js
134+
{
135+
"data": [{
136+
"type": "identities",
137+
"id": 3,
138+
"attributes": {
139+
...
140+
},
141+
"relationships": {
142+
"home_town": {
143+
"data": [{
144+
"type": "home_town",
145+
"id": 3
146+
}]
147+
}
148+
}
149+
}]
150+
}
151+
```
152+
153+
When set to dasherize:
154+
155+
156+
``` js
157+
{
158+
"data": [{
159+
"type": "identities",
160+
"id": 3,
161+
"attributes": {
162+
...
163+
},
164+
"relationships": {
165+
"home_town": {
166+
"data": [{
167+
"type": "home-town",
168+
"id": 3
169+
}]
170+
}
171+
}
172+
}]
173+
}
174+
```
175+
176+
123177
<!--
124178
### Relationships
125179
### Links

0 commit comments

Comments
 (0)