Using includes method in default_scope in Rails 5 models instead of within the controller

281 views Asked by At

I understand that generally it is better to avoid having default scopes in Rails models, however, as some associations are always needed & instead of having the .includes method in the controller every time for the model, I prefer having that includes in a default scope in the model itself.

Is there any major drawback of this change (moving .includes to model's default_scope instead of controller)?

So for example:

Instead of having in the controller:

Brand.includes(:car_model)

I want to have includes in the Brand model itself this:

default_scope { includes(:car_model) }

Note:

From what I see is that bullet is now saying avoid eager load to avoid this includes instead of the use eager load that I had before on the same model & included association.

0

There are 0 answers