Skip to content

Commit b0a16f3

Browse files
committed
Update README.md
1 parent 656ef92 commit b0a16f3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,20 @@ Note that the JSON:API spec distinguishes in how null/empty is handled for singl
149149

150150
### Custom attributes
151151

152-
By default the serializer looks for the same name of the attribute on the object it is given. You can customize this behavior by providing a block to the attribute:
152+
By default the serializer looks for the same name of the attribute on the object it is given. You can customize this behavior by providing a block to `attribute`, `has_one`, or `has_many`:
153153

154154
```ruby
155155
attribute :content do
156156
object.body
157157
end
158+
159+
has_one :comment do
160+
Comment.where(post: object).take!
161+
end
162+
163+
has_many :authors do
164+
Author.where(post: object)
165+
end
158166
```
159167

160168
The block is evaluated within the serializer instance, so it has access to the `object` and `context` instance variables.

0 commit comments

Comments
 (0)