You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default fast_jsonapi underscores the key names. It supports the same key transforms that are supported by AMS. Here is the syntax of specifying a key transform
156
+
157
+
By default fast_jsonapi underscores the key names. It supports the same key transforms that are supported by AMS. Here is the syntax of specifying a key transform:
155
158
156
159
```ruby
157
160
classMovieSerializer
@@ -160,7 +163,8 @@ class MovieSerializer
160
163
set_key_transform :camel
161
164
end
162
165
```
163
-
Here are examples of how these options transform the keys
166
+
167
+
Here are examples of how these options transform the keys.
By default fast_jsonapi does not pluralize type names. You can turn pluralization on using this syntax:
179
+
180
+
```ruby
181
+
classAwardSerializer
182
+
includeFastJsonapi::ObjectSerializer
183
+
belongs_to :actor
184
+
pluralize_type true# "award" => "awards"
185
+
end
186
+
```
187
+
188
+
Relationship types are not automatically pluralized, even when their base types have `pluralize_type` set. Pluralization can be enabled in the relationship definition.
The most common use case for this feature is to easily migrate from serialization engines that pluralize by default, such as AMS.
198
+
172
199
### Attributes
173
-
Attributes are defined in FastJsonapi using the `attributes` method. This method is also aliased as `attribute`, which is useful when defining a single attribute.
174
200
175
-
By default, attributes are read directly from the model property of the same name. In this example, `name` is expected to be a property of the object being serialized:
201
+
Attributes are defined in FastJsonapi using the `attributes` method. This method is also aliased as `attribute`, which is useful when defining a single attribute.
202
+
203
+
By default, attributes are read directly from the model property of the same name. In this example, `name` is expected to be a property of the object being serialized:
176
204
177
205
```ruby
178
206
classMovieSerializer
@@ -221,6 +249,7 @@ end
221
249
```
222
250
223
251
### Links Per Object
252
+
224
253
Links are defined in FastJsonapi using the `link` method. By default, links are read directly from the model property of the same name. In this example, `public_url` is expected to be a property of the object being serialized.
225
254
226
255
You can configure the method to use on the object for example a link with key `self` will get set to the value returned by a method called `url` on the movie object.
@@ -276,6 +305,7 @@ This will create a `self` reference for the relationship, and a `related` link f
276
305
### Meta Per Resource
277
306
278
307
For every resource in the collection, you can include a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
308
+
279
309
```ruby
280
310
meta do |movie|
281
311
{
@@ -287,7 +317,7 @@ end
287
317
288
318
### Compound Document
289
319
290
-
Support for top-level and nested included associations through `options[:include]`.
320
+
Support for top-level and nested included associations through `options[:include]`.
291
321
292
322
```ruby
293
323
options = {}
@@ -331,10 +361,11 @@ options[:is_collection]
331
361
was introduced to be able to have precise control this behavior
332
362
333
363
-`nil` or not provided: will try to autodetect single vs collection (please, see notes above)
334
-
-`true` will always treat input resource as *collection*
335
-
-`false` will always treat input resource as *single object*
364
+
-`true` will always treat input resource as _collection_
365
+
-`false` will always treat input resource as _single object_
336
366
337
367
### Caching
368
+
338
369
Requires a `cache_key` method be defined on model:
set_type | Type name of Object | ```set_type :movie```
452
-
key | Key of Object | ```belongs_to :owner, key: :user```
453
-
set_id | ID of Object | ```set_id :owner_id``` or ```set_id { |record| "#{record.name.downcase}-#{record.id}" }```
454
-
cache_options | Hash to enable caching and set cache length | ```cache_options enabled: true, cache_length: 12.hours, race_condition_ttl: 10.seconds```
455
-
id_method_name | Set custom method name to get ID of an object (If block is provided for the relationship, `id_method_name` is invoked on the return value of the block instead of the resource object) | ```has_many :locations, id_method_name: :place_ids```
456
-
object_method_name | Set custom method name to get related objects | ```has_many :locations, object_method_name: :places```
457
-
record_type | Set custom Object Type for a relationship | ```belongs_to :owner, record_type: :user```
458
-
serializer | Set custom Serializer for a relationship | ```has_many :actors, serializer: :custom_actor``` or ```has_many :actors, serializer: MyApp::Api::V1::ActorSerializer```
459
-
polymorphic | Allows different record types for a polymorphic association | ```has_many :targets, polymorphic: true```
460
-
polymorphic | Sets custom record types for each object class in a polymorphic association | ```has_many :targets, polymorphic: { Person => :person, Group => :group }```
|set_type | Type name of Object |`set_type :movie`|
483
+
|key | Key of Object |`belongs_to :owner, key: :user`|
484
+
|set_id | ID of Object |`set_id :owner_id` or `set_id { |record| "#{record.name.downcase}-#{record.id}" }`|
485
+
|cache_options | Hash to enable caching and set cache length |`cache_options enabled: true, cache_length: 12.hours, race_condition_ttl: 10.seconds`|
486
+
|id_method_name | Set custom method name to get ID of an object (If block is provided for the relationship, `id_method_name` is invoked on the return value of the block instead of the resource object) |`has_many :locations, id_method_name: :place_ids`|
487
+
|object_method_name | Set custom method name to get related objects |`has_many :locations, object_method_name: :places`|
488
+
|record_type | Set custom Object Type for a relationship |`belongs_to :owner, record_type: :user`|
489
+
|serializer | Set custom Serializer for a relationship |`has_many :actors, serializer: :custom_actor` or `has_many :actors, serializer: MyApp::Api::V1::ActorSerializer`|
490
+
|polymorphic | Allows different record types for a polymorphic association |`has_many :targets, polymorphic: true`|
491
+
|polymorphic | Sets custom record types for each object class in a polymorphic association |`has_many :targets, polymorphic: { Person => :person, Group => :group }`|
Please see [contribution check](https://github.com/Netflix/fast_jsonapi/blob/master/CONTRIBUTING.md) for more details on contributing
495
529
496
530
### Running Tests
531
+
497
532
We use [RSpec](http://rspec.info/) for testing. We have unit tests, functional tests and performance tests. To run tests use the following command:
0 commit comments