You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -270,6 +270,55 @@ be output as attributes you can specify a whitelist of attributes for each type.
270
270
#### note
271
271
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`
272
272
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
+
273
322
## Custom Serialization
274
323
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.
0 commit comments