mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Added examples to use class_name options for association.
This commit is contained in:
parent
41f2e11c4d
commit
f3b202746b
@ -81,6 +81,7 @@ e.g.
|
|||||||
```ruby
|
```ruby
|
||||||
has_one :bio
|
has_one :bio
|
||||||
has_one :blog, key: :site
|
has_one :blog, key: :site
|
||||||
|
has_one :blog, class_name: "Blog"
|
||||||
has_one :maker, virtual_value: { id: 1 }
|
has_one :maker, virtual_value: { id: 1 }
|
||||||
|
|
||||||
has_one :blog do |serializer|
|
has_one :blog do |serializer|
|
||||||
@ -114,6 +115,7 @@ e.g.
|
|||||||
has_many :comments
|
has_many :comments
|
||||||
has_many :comments, key: :reviews
|
has_many :comments, key: :reviews
|
||||||
has_many :comments, serializer: CommentPreviewSerializer
|
has_many :comments, serializer: CommentPreviewSerializer
|
||||||
|
has_many :comments, class_name: "Comment"
|
||||||
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
||||||
has_many :comments, key: :last_comments do
|
has_many :comments, key: :last_comments do
|
||||||
last(1)
|
last(1)
|
||||||
@ -127,6 +129,7 @@ e.g.
|
|||||||
```ruby
|
```ruby
|
||||||
belongs_to :author, serializer: AuthorPreviewSerializer
|
belongs_to :author, serializer: AuthorPreviewSerializer
|
||||||
belongs_to :author, key: :writer
|
belongs_to :author, key: :writer
|
||||||
|
belongs_to :author, class_name: "Author"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :blog
|
belongs_to :blog
|
||||||
def blog
|
def blog
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user