Skip to content

Commit 9aec7c5

Browse files
Erolshishirmk
authored andcommitted
Add README instructions for using sparse fieldsets
1 parent fa19413 commit 9aec7c5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Fast JSON API serialized 250 records in 3.01 ms
3232
* [Params](#params)
3333
* [Conditional Attributes](#conditional-attributes)
3434
* [Conditional Relationships](#conditional-relationships)
35+
* [Sparse Fieldsets](#sparse-fieldsets)
3536
* [Contributing](#contributing)
3637

3738

@@ -388,6 +389,21 @@ serializer = MovieSerializer.new(movie, { params: { admin: current_user.admin? }
388389
serializer.serializable_hash
389390
```
390391

392+
### Sparse Fieldsets
393+
394+
Attributes and relationships can be selectively returned per record type by using the `fields` option.
395+
396+
```ruby
397+
class MovieSerializer
398+
include FastJsonapi::ObjectSerializer
399+
400+
attributes :name, :year
401+
end
402+
403+
serializer = MovieSerializer.new(movie, { fields: { movie: [:name] } })
404+
serializer.serializable_hash
405+
```
406+
391407
### Customizable Options
392408

393409
Option | Purpose | Example

0 commit comments

Comments
 (0)