Skip to content

Commit 1db5b9e

Browse files
committed
docs(configuration): Add foreignKeys docs
Add documentation to README.md to describe to users how to use the new foreignKeys configuration option
1 parent 1a9d47d commit 1db5b9e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,55 @@ be output as attributes you can specify a whitelist of attributes for each type.
270270
#### note
271271
The attributes arrays are keyed by type not by model name. Type is the term used by JSON API to describe the resource type in question and while not required by JSON API it is usually plural. In `loopback-component-jsonapi` it is whatever the models `plural` is set to in `model.json`. So in our example above we defined: `"posts": ["title", "content"]` as the resource type for the `post` model is `posts`
272272

273+
### foreignKeys
274+
Allows configuration of whether the component should expose foreign keys (which the jsonapi spec considers
275+
implementation details) from the attributes hash.
276+
277+
#### examples
278+
279+
1. Always expose foreign keys for all models
280+
```js
281+
{
282+
...
283+
foreignKeys: true,
284+
...
285+
}
286+
```
287+
288+
2. Never expose foreign keys for any models (default behaviour)
289+
```js
290+
{
291+
...
292+
foreignKeys: false,
293+
...
294+
}
295+
```
296+
297+
3. Only expose foreign keys for the commeht model
298+
```js
299+
{
300+
...
301+
foreignKeys: [
302+
{model: 'comment'}
303+
],
304+
...
305+
}
306+
```
307+
308+
4. Only expose foreign keys for the comment model findById method. eg. `GET /api/comments/1`
309+
```js
310+
{
311+
...
312+
foreignKeys: [
313+
{model: 'comment', method: 'findById'}
314+
],
315+
...
316+
}
317+
```
318+
319+
- Type: `boolean|array`
320+
- Default: `false`
321+
273322
## Custom Serialization
274323
For occasions where you need greater control over the serialization process, you can implement a custom serialization function for each model as needed. This function will be used instead of the regular serialization process.
275324

0 commit comments

Comments
 (0)