... | ... | @@ -7,8 +7,11 @@ This method allows defining a conditional value that, if present in the result s |
|
|
In any model, you just need to call `dynamic_attribute` method, passing an name for it and the block that will be called in case the attribute is not present.
|
|
|
|
|
|
```ruby
|
|
|
dynamic_attribute(:last_comment) do
|
|
|
comments.order(id: :desc).first.content
|
|
|
# models/user.rb
|
|
|
class User < ActiveRecord::Base
|
|
|
dynamic_attribute(:last_comment) do
|
|
|
comments.order(id: :desc).first.content
|
|
|
end
|
|
|
end
|
|
|
```
|
|
|
|
... | ... | |