Skip to content

Commit f3a19bd

Browse files
authored
Merge pull request #2260 from abhaynikam/2258-fix-class-name-documentation
[docs] Fix class name documentation
2 parents 9c77bb6 + 4559774 commit f3a19bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

docs/general/serializers.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Where:
6565
- `virtual_value:`
6666
- `polymorphic:` defines if polymorphic relation type should be nested in serialized association.
6767
- `type:` the resource type as used by JSON:API, especially on a `belongs_to` relationship.
68-
- `class_name:` used to determine `type` when `type` not given
68+
- `class_name:` the (String) model name used to determine `type`, when `type` is not given. e.g. `class_name: "Comment"` would imply the type `comments`
6969
- `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object.
7070
- `namespace:` used when looking up the serializer and `serializer` is not given. Falls back to the parent serializer's `:namespace` instance options, which, when present, comes from the render options. See [Rendering#namespace](rendering.md#namespace] for more details.
7171
- optional: `&block` is a context that returns the association's attributes.
@@ -81,6 +81,7 @@ e.g.
8181
```ruby
8282
has_one :bio
8383
has_one :blog, key: :site
84+
has_one :blog, class_name: "Blog"
8485
has_one :maker, virtual_value: { id: 1 }
8586

8687
has_one :blog do |serializer|
@@ -114,6 +115,7 @@ e.g.
114115
has_many :comments
115116
has_many :comments, key: :reviews
116117
has_many :comments, serializer: CommentPreviewSerializer
118+
has_many :comments, class_name: "Comment"
117119
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
118120
has_many :comments, key: :last_comments do
119121
last(1)
@@ -127,6 +129,7 @@ e.g.
127129
```ruby
128130
belongs_to :author, serializer: AuthorPreviewSerializer
129131
belongs_to :author, key: :writer
132+
belongs_to :author, class_name: "Author"
130133
belongs_to :post
131134
belongs_to :blog
132135
def blog
@@ -294,7 +297,7 @@ end
294297
Whether you write the method as above or as `object.comments.where(created_by: scope)`
295298
is a matter of preference (assuming `scope_name` has been set).
296299

297-
Keep in mind that the scope can be set to any available controller reference. This can be utilized to provide access to any other data scopes or presentation helpers.
300+
Keep in mind that the scope can be set to any available controller reference. This can be utilized to provide access to any other data scopes or presentation helpers.
298301

299302
##### Controller Authorization Context
300303

@@ -381,7 +384,7 @@ class PostsController < ActionController::Base
381384
end
382385
end
383386
```
384-
Note that any controller reference which provides the desired scope is acceptable, such as another controller method for loading a different resource or reference to helpers. For example, `ActionController::API` does not include `ActionView::ViewContext`, and would need a different reference for passing any helpers into a serializer via `serialization_scope`.
387+
Note that any controller reference which provides the desired scope is acceptable, such as another controller method for loading a different resource or reference to helpers. For example, `ActionController::API` does not include `ActionView::ViewContext`, and would need a different reference for passing any helpers into a serializer via `serialization_scope`.
385388

386389
#### #read_attribute_for_serialization(key)
387390

0 commit comments

Comments
 (0)