mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Support overriding association methods
You can override associations to define custom scope on them.
This commit is contained in:
16
README.md
16
README.md
@@ -146,6 +146,22 @@ call:
|
||||
render json: @post, root: "articles"
|
||||
```
|
||||
|
||||
### Overriding association methods
|
||||
|
||||
If you want to override any association, you can use:
|
||||
|
||||
```ruby
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :id, :body
|
||||
|
||||
has_many :comments
|
||||
|
||||
def comments
|
||||
object.comments.active
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
### Built in Adapters
|
||||
|
||||
#### JSONAPI
|
||||
|
||||
Reference in New Issue
Block a user