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
+26-3Lines changed: 26 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,15 +245,38 @@ class MovieSerializer
245
245
end
246
246
```
247
247
248
-
### Meta Per Resource
249
-
250
-
For every resource in the collection, you can include a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
248
+
#### Links on a Relationship
251
249
250
+
You can specify [relationship links](http://jsonapi.org/format/#document-resource-object-relationships) by using the `links:` option on the serializer. Relationship links in JSON API are useful if you want to load a parent document and then load associated documents later due to size constraints (see [related resource links](http://jsonapi.org/format/#document-resource-object-related-resource-links))
252
251
253
252
```ruby
254
253
classMovieSerializer
255
254
includeFastJsonapi::ObjectSerializer
256
255
256
+
has_many :actors, links: {
257
+
self::url,
258
+
related:-> (object) {
259
+
"https://movies.com/#{object.id}/actors"
260
+
}
261
+
}
262
+
end
263
+
```
264
+
265
+
This will create a `self` reference for the relationship, and a `related` link for loading the actors relationship later. NB: This will not automatically disable loading the data in the relationship, you'll need to do that using the `lazy_load_data` option:
266
+
267
+
```ruby
268
+
has_many :actors, lazy_load_data:true, links: {
269
+
self::url,
270
+
related:-> (object) {
271
+
"https://movies.com/#{object.id}/actors"
272
+
}
273
+
}
274
+
```
275
+
276
+
### Meta Per Resource
277
+
278
+
For every resource in the collection, you can include a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
0 commit comments