mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Prefer explicitly yielding the serializer, per groyoh
This commit is contained in:
@@ -48,6 +48,18 @@ has_one :blog, key: :site
|
||||
has_one :maker, virtual_value: { id: 1 }
|
||||
```
|
||||
|
||||
``ruby
|
||||
has_one :blog do |serializer|
|
||||
serializer.cached_blog
|
||||
end
|
||||
|
||||
def cached_blog
|
||||
cache_store.fetch("cached_blog:#{object.updated_at}") do
|
||||
Blog.find(object.blog_id)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### ::has_many
|
||||
|
||||
e.g.
|
||||
|
||||
Reference in New Issue
Block a user