Skip to content

Commit 0669901

Browse files
committed
Merge pull request #1201 from hut8/master
Add documentation about wildcard includes
2 parents 34d6571 + a32ad43 commit 0669901

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ resources in the `"included"` member when the resource names are included in the
213213
render @posts, include: 'author,comments,comments.author'
214214
```
215215

216+
In addition, two types of wildcards may be used. `*` includes one level of associations, and `**` includes all recursively. These can be combined with other paths.
217+
218+
```ruby
219+
render @posts, include: '**' # or '*' for a single layer
220+
```
221+
222+
The following would render posts and include the author, the author's comments, and every resource referenced by the author's comments (recursively). It could be combined, like above, with other paths in any combination desired.
223+
224+
```ruby
225+
render @posts, include: 'author.comments.**'
226+
```
227+
228+
The JSON API [specifies](http://jsonapi.org/format/#fetching-includes) that the user may supply a parameter specifying which related resources are to be included:
229+
230+
```ruby
231+
render @posts, include: params[:include]
232+
```
233+
234+
This raises some security concerns since the user could pass in `include=**`, so filter the values for `include` appropriately if you decide to support this JSON API feature.
235+
216236
## Installation
217237

218238
Add this line to your application's Gemfile:

0 commit comments

Comments
 (0)