Thoughts on an implementation like the one below to allow for configurable eager loading on the User model?
weilandia opened this issue · comments
Nick Weiland commented
Thoughts on an implementation like the one below to allow for configurable eager loading on the User model?
# The ActiveRecord class that represents users in your application.
# Defaults to `::User`.
# @return [ActiveRecord::Base]
attr_writer :user_model
# An optional array of records to eager load with current_user
# Defaults to []
# @return [Array]
attr_writer :eager_load
...
# The class representing the configured user model.
# In the default configuration, this is the `User` class.
# @return [Class]
def user_model
model = (@user_model || "User").to_s.constantize
model.send(:includes, @eager_load)
end
Nick Weiland commented
default scope is probably clearer