File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7878class MovieSerializer
7979 include FastJsonapi ::ObjectSerializer
8080 set_type :movie # optional
81+ set_id :owner_id # optional
8182 attributes :name , :year
8283 has_many :actors
8384 belongs_to :owner , record_type: :user
@@ -114,7 +115,7 @@ json_string = MovieSerializer.new(movie).serialized_json
114115``` json
115116{
116117 "data" : {
117- "id" : " 232 " ,
118+ "id" : " 3 " ,
118119 "type" : " movie" ,
119120 "attributes" : {
120121 "name" : " test movie" ,
238239Option | Purpose | Example
239240------------ | ------------- | -------------
240241set_type | Type name of Object | ``` set_type :movie ```
242+ set_id | ID of Object | ``` set_id :owner_id ```
241243cache_options | Hash to enable caching and set cache length | ``` cache_options enabled: true, cache_length: 12.hours ```
242244id_method_name | Set custom method name to get ID of an object | ``` has_many :locations, id_method_name: :place_ids ```
243245object_method_name | Set custom method name to get related objects | ``` has_many :locations, object_method_name: :places ```
You can’t perform that action at this time.
0 commit comments