Rails 6.1 has added strict_loading mode to prevent lazy loading of associations. When the strict_loading mode is used, the associated records will have to be eager loaded using includes else a ActiveRecord::StrictLoadingViolationError will be raised.

>> p = Project.strict_loading.find_by(id: 'abe99c60-56c4-461e-bd59-63418a719e0d')
>> p.commits.to_a


>> p = Project.includes(:commits).strict_loading.find_by(id: 'abe99c60-56c4-461e-bd59-63418a719e0d')
>> p.commits.first.post


The strict_loading mode can also be declared as an option on the association to enforce eager loading of associated records.

class Project < ApplicationRecord
end

>> p = Project.first
>> p.commits.first

The strict_loading mode, helps in avoiding N + 1 that might be otherwise missed. Since these are now baked into Rails, we have a better and predictable result, unlike some issues that the bullet gem might face.