From 9aec7c58ede732b19643309383c0e74d289efeb9 Mon Sep 17 00:00:00 2001 From: Erol Date: Tue, 17 Jul 2018 12:02:58 +0800 Subject: [PATCH] Add README instructions for using sparse fieldsets --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index c812eac..a03e1a8 100644 --- a/README.md +++ b/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