|
65 | 65 | - `virtual_value:`
|
66 | 66 | - `polymorphic:` defines if polymorphic relation type should be nested in serialized association.
|
67 | 67 | - `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` |
69 | 69 | - `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object.
|
70 | 70 | - `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.
|
71 | 71 | - optional: `&block` is a context that returns the association's attributes.
|
|
81 | 81 | ```ruby
|
82 | 82 | has_one :bio
|
83 | 83 | has_one :blog, key: :site
|
| 84 | +has_one :blog, class_name: "Blog" |
84 | 85 | has_one :maker, virtual_value: { id: 1 }
|
85 | 86 |
|
86 | 87 | has_one :blog do |serializer|
|
|
114 | 115 | has_many :comments
|
115 | 116 | has_many :comments, key: :reviews
|
116 | 117 | has_many :comments, serializer: CommentPreviewSerializer
|
| 118 | +has_many :comments, class_name: "Comment" |
117 | 119 | has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
|
118 | 120 | has_many :comments, key: :last_comments do
|
119 | 121 | last(1)
|
|
127 | 129 | ```ruby
|
128 | 130 | belongs_to :author, serializer: AuthorPreviewSerializer
|
129 | 131 | belongs_to :author, key: :writer
|
| 132 | +belongs_to :author, class_name: "Author" |
130 | 133 | belongs_to :post
|
131 | 134 | belongs_to :blog
|
132 | 135 | def blog
|
|
294 | 297 | Whether you write the method as above or as `object.comments.where(created_by: scope)`
|
295 | 298 | is a matter of preference (assuming `scope_name` has been set).
|
296 | 299 |
|
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. |
298 | 301 |
|
299 | 302 | ##### Controller Authorization Context
|
300 | 303 |
|
@@ -381,7 +384,7 @@ class PostsController < ActionController::Base
|
381 | 384 | end
|
382 | 385 | end
|
383 | 386 | ```
|
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`. |
385 | 388 |
|
386 | 389 | #### #read_attribute_for_serialization(key)
|
387 | 390 |
|
|
0 commit comments