diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index d84191e435..8d0245d516 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -9,7 +9,7 @@ #or ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table' ``` - + And also use it passing a hash, with one or more keys, where the key is the adapter @@ -17,7 +17,7 @@ ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = { mysql2: ['--no-defaults', '--skip-add-drop-table'], postgres: '--no-tablespaces' - } + } ``` *Gustavo Gonzalez* @@ -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 # => # - user = User.first - user.stict_loading!(false) - user.articles - # => # + user.strict_loading!(true) # => true + user.bookmarks # => ActiveRecord::StrictLoadingViolationError + + user.strict_loading!(false) # => false + user.bookmarks # => # + user.articles.strict_loading!(false) # => # ``` *Ayrton De Craene* diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index a8d9fe2876..889c1dad58 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -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 + # => # def strict_loading!(value = true) @strict_loading = value end