Add README instructions for using sparse fieldsets
This commit is contained in:
parent
fa194133fa
commit
9aec7c58ed
16
README.md
16
README.md
@ -32,6 +32,7 @@ Fast JSON API serialized 250 records in 3.01 ms
|
||||
* [Params](#params)
|
||||
* [Conditional Attributes](#conditional-attributes)
|
||||
* [Conditional Relationships](#conditional-relationships)
|
||||
* [Sparse Fieldsets](#sparse-fieldsets)
|
||||
* [Contributing](#contributing)
|
||||
|
||||
|
||||
@ -388,6 +389,21 @@ serializer = MovieSerializer.new(movie, { params: { admin: current_user.admin? }
|
||||
serializer.serializable_hash
|
||||
```
|
||||
|
||||
### Sparse Fieldsets
|
||||
|
||||
Attributes and relationships can be selectively returned per record type by using the `fields` option.
|
||||
|
||||
```ruby
|
||||
class MovieSerializer
|
||||
include FastJsonapi::ObjectSerializer
|
||||
|
||||
attributes :name, :year
|
||||
end
|
||||
|
||||
serializer = MovieSerializer.new(movie, { fields: { movie: [:name] } })
|
||||
serializer.serializable_hash
|
||||
```
|
||||
|
||||
### Customizable Options
|
||||
|
||||
Option | Purpose | Example
|
||||
|
Loading…
x
Reference in New Issue
Block a user