mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
#133 making :serializer and :polymorphic documentation less verbose
This commit is contained in:
parent
257adfc80e
commit
9cd472c160
26
README.md
26
README.md
@ -328,35 +328,11 @@ class PostSerializer < ActiveModel::Serializer
|
||||
end
|
||||
```
|
||||
|
||||
Use the `:serializer` option to specify a custom serializer class:
|
||||
You may also use the `:serializer` option to specify a custom serializer class and the `:polymorphic` option to specify an association that is polymorphic (STI), e.g.:
|
||||
|
||||
```ruby
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :id, :title, :body
|
||||
has_one :author
|
||||
has_many :comments, :serializer => CommentShortSerializer
|
||||
|
||||
def include_associations!
|
||||
include! :author if scope.admin?
|
||||
include! :comments unless object.comments_disabled?
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Use the `:polymorphic` option to specify an association that is polymorphic (STI):
|
||||
|
||||
```ruby
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :id, :title, :body
|
||||
has_one :author
|
||||
has_many :comments
|
||||
has_one :reviewer, :polymorphic => true
|
||||
|
||||
def include_associations!
|
||||
include! :author if scope.admin?
|
||||
include! :comments unless object.comments_disabled?
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Embedding Associations
|
||||
|
||||
Loading…
Reference in New Issue
Block a user