Skip to content

Commit 966b350

Browse files
committed
update readme
1 parent 63f905a commit 966b350

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ By default, attributes are read directly from the model property of the same nam
174174
```ruby
175175
class MovieSerializer
176176
include FastJsonapi::ObjectSerializer
177-
177+
178178
attribute :name
179179
end
180180
```
@@ -184,9 +184,9 @@ Custom attributes that must be serialized but do not exist on the model can be d
184184
```ruby
185185
class MovieSerializer
186186
include FastJsonapi::ObjectSerializer
187-
187+
188188
attributes :name, :year
189-
189+
190190
attribute :name_with_year do |object|
191191
"#{object.name} (#{object.year})"
192192
end
@@ -198,7 +198,7 @@ The block syntax can also be used to override the property on the object:
198198
```ruby
199199
class MovieSerializer
200200
include FastJsonapi::ObjectSerializer
201-
201+
202202
attribute :name do |object|
203203
"#{object.name} Part 2"
204204
end
@@ -254,7 +254,7 @@ related to a current authenticated user. The `options[:params]` value covers the
254254
cases by allowing you to pass in a hash of additional parameters necessary for
255255
your use case.
256256

257-
Leveraging the new params is easy, when you define a custom attribute with a
257+
Leveraging the new params is easy, when you define a custom attribute or relationship with a
258258
block you opt-in to using params by adding it as a block parameter.
259259

260260
```ruby
@@ -267,6 +267,11 @@ class MovieSerializer
267267
# in here, params is a hash containing the `:current_user` key
268268
params[:current_user].is_employee? ? true : false
269269
end
270+
271+
belongs_to :primary_agent do |movie, params|
272+
# in here, params is a hash containing the `:current_user` key
273+
params[:current_user].is_employee? ? true : false
274+
end
270275
end
271276

272277
# ...
@@ -275,7 +280,7 @@ serializer = MovieSerializer.new(movie, {params: {current_user: current_user}})
275280
serializer.serializable_hash
276281
```
277282

278-
Custom attributes that only receive the resource are still possible by defining
283+
Custom attributes and relationships that only receive the resource are still possible by defining
279284
the block to only receive one argument.
280285

281286
### Customizable Options

0 commit comments

Comments
 (0)