mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixes strict_loading! documentation
- Fixes typo in the changelog for strict_loading. - Fixes the example in the changelog for strict_loading. The `strict_loading!` on ActiveRecord object does not disable strict loading on the association if set to strict loading. The example spoke otherwise so updated in a manner to make it more clear. - Add method level dcoumentation as changelog was only way to communicate how strict_loading could be disabled on the record.
This commit is contained in:
parent
af9c910db7
commit
4762721d03
2 changed files with 21 additions and 10 deletions
|
@ -38,17 +38,20 @@
|
|||
|
||||
```ruby
|
||||
class User < ApplicationRecord
|
||||
has_many :bookmarks
|
||||
has_many :articles, strict_loading: true
|
||||
end
|
||||
|
||||
user = User.first
|
||||
user.articles
|
||||
# => ActiveRecord::StrictLoadingViolationError
|
||||
user.articles # => ActiveRecord::StrictLoadingViolationError
|
||||
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
||||
|
||||
user = User.first
|
||||
user.stict_loading!(false)
|
||||
user.articles
|
||||
# => #<ActiveRecord::Associations::CollectionProxy>
|
||||
user.strict_loading!(true) # => true
|
||||
user.bookmarks # => ActiveRecord::StrictLoadingViolationError
|
||||
|
||||
user.strict_loading!(false) # => false
|
||||
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
||||
user.articles.strict_loading!(false) # => #<ActiveRecord::Associations::CollectionProxy>
|
||||
```
|
||||
|
||||
*Ayrton De Craene*
|
||||
|
|
|
@ -663,9 +663,17 @@ module ActiveRecord
|
|||
# if the record tries to lazily load an association.
|
||||
#
|
||||
# user = User.first
|
||||
# user.strict_loading!
|
||||
# user.comments.to_a
|
||||
# user.strict_loading! # => true
|
||||
# user.comments
|
||||
# => ActiveRecord::StrictLoadingViolationError
|
||||
#
|
||||
# strict_loading! accepts a boolean argument to specify whether
|
||||
# to enable or disable strict loading mode.
|
||||
#
|
||||
# user = User.first
|
||||
# user.strict_loading!(false) # => false
|
||||
# user.comments
|
||||
# => #<ActiveRecord::Associations::CollectionProxy>
|
||||
def strict_loading!(value = true)
|
||||
@strict_loading = value
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue