Rails strict_loading mode is to stop lazy loading of associations.
When the strict_loading
mode is used,
the related information should be keen loaded utilizing contains
else a ActiveRecord::StrictLoadingViolationError
shall be raised.
This mode helps in figuring out
and fixing N+1 question points by making certain that sure associations are loaded eagerly to keep away from efficiency bottlenecks.
Earlier than
Strict loading in :n_plus_one_only
mode is particularly designed to deal with efficiency points that may come up when navigating by means of deeply nested associations
It permits direct loading of associations whereas proscribing deeper traversal, stopping potential N+1 question points
and surprises associated to ordering inconsistencies.
The place as navigating by means of deeply nested associations throws error
After
Strict loading utilizing :n_plus_one_only
doesn’t eagerly load youngster associations.
With this change, youngster associations are not eagerly loaded, to match supposed conduct
and to stop non-deterministic order points brought on by calling strategies like first or final. As first
and final don’t trigger an N+1 by themselves, calling youngster associations will not elevate.
It means associations are eagerly loaded
and youngster associations are lazy loaded.
Abstract
With Strict loading, we will stop lazy loading of associations because it raises ActiveRecord::StrictLoadingViolationError
if the related information will not be keen loaded.
However With strict_loading!(mode: :n_plus_one_only)
, associations are eagerly loaded
and youngster associations are lazy loaded.