Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.10] add docs for include #2081

Merged
merged 3 commits into from
Mar 28, 2017

Conversation

charlie-wasp
Copy link
Contributor

Purpose

This PR addresses #1243, adding missing docs about include option for not JSON API adapters.

Related GitHub issues

#1243

This is my first documentation PR, and I will be glad to make it better! :)

@mention-bot
Copy link

@charlie-wasp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bf4, @beauby and @remear to be potential reviewers.

@charlie-wasp charlie-wasp changed the title 1243 add docs for include [0.10] add docs for include Mar 17, 2017
@charlie-wasp charlie-wasp force-pushed the 1243-add-docs-for-include branch from 8aa2b42 to 30c509d Compare March 17, 2017 17:04
@charlie-wasp charlie-wasp force-pushed the 1243-add-docs-for-include branch from 30c509d to 4f0b60d Compare March 17, 2017 17:08
Copy link
Member

@bf4 bf4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 So excited for this. Just some thoughts.


```ruby
render json: @posts, include: ['author', 'comments', 'comments.author']
# or
render json: @posts, include: 'author,comments,comments.author'
```
**Note:** Serializer classes must declare associations explicitly, using `belongs_to` and `has_many` and etc., for `include` option to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:

Which serializer associations are rendered can be specified using the include option. The option usage is consistent with the include option in the JSON API spec, but is available in all adapters. The default include for the JSON API adapter is no associations. The default for the JSON and Attributes adapters is all associations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to also have an example that mixes fields with include unless there's another somewhere.


```ruby
render json: @posts, include: ['author', 'comments', 'comments.author']
# or
render json: @posts, include: 'author,comments,comments.author'
```
**Note:** Serializer classes must declare associations explicitly, using `belongs_to` and `has_many` and etc., for `include` option to work.

For JSON API adapter associated resources will be gathered in the `"included"` member.

In addition, two types of wildcards may be used:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe note the wildcards are AMS-specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid, I don't fully understand, what does "AMS-specific" mean. Can you elaborate, please?

@charlie-wasp charlie-wasp force-pushed the 1243-add-docs-for-include branch from 4c051a1 to ad13e2c Compare March 19, 2017 14:27
@charlie-wasp
Copy link
Contributor Author

@bf4 I tried to embrace your thoughts :)

It will include the associated resources in the `"included"` member
when the resource names are included in the `include` option.
Including nested associated resources is also supported.
Which [serializer associations](https://github.com/rails-api/active_model_serializers/blob/master/docs/general/serializers.md#associations) are rendered can be specified using the `include` option. The option usage is consistent with [the include option in the JSON API spec](http://jsonapi.org/format/#fetching-includes), but is available in all adapters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/but is/and is

@@ -182,6 +184,20 @@ It could be combined, like above, with other paths in any combination desired.
render json: @posts, include: 'author.comments.**'
```

**Note:** Wildcards are AMS-specific, they are not part of the JSON API spec.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/AMS/ActiveModelSerializers


- a String composed of a comma-separated list of [relationship paths](http://jsonapi.org/format/#fetching-includes).
- an Array of Symbols and Hashes.
- a mix of both.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@bf4
Copy link
Member

bf4 commented Mar 21, 2017

@charlie-wasp I think it looks great! Please make the two word changes and add yourself to the changelog under misc

@charlie-wasp
Copy link
Contributor Author

@bf4 done!

@charlie-wasp
Copy link
Contributor Author

@bf4 Hello, any updates on this?

@bf4
Copy link
Member

bf4 commented Mar 28, 2017

@charlie-wasp Sorry for the delay :( great job!

@bf4 bf4 merged commit 68f8a1a into rails-api:0-10-stable Mar 28, 2017
bf4 pushed a commit that referenced this pull request Mar 28, 2017
* Add docs for `include` option in the adapter
GregPK pushed a commit to GregPK/active_model_serializers that referenced this pull request Apr 25, 2017
* Add docs for `include` option in the adapter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants