Strict Loading Associations can prevent n+1 queries

Updated . Posted . Visible to the public.

Rails 6.1 has a "strict loading" mode that forces the developer to preload any association they plan to use. Associations no longer load lazily. An error is raised when reading an association that was not preloaded.

Enabling strict loading is a tool to prevent n+1 queries Show archive.org snapshot .

Strict loading can be enabled for individual records, for a single association, for an entire model, or globally for all models.

See the linked article for details.

Henning Koch
Last edit
Jonas Schiele
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2021-10-13 10:33)