我是铁杆的新手,并试图了解我应该把我的.includes
放在哪里。
例如,我的控制器中有以下内容:
@offices = Office
.includes(:services, :location, :manager)
这应该转移到Office模型吗?如果是这样,应该怎么做?
如果要在多个位置执行此操作,可以将此逻辑放在模型上
class Office < ApplicationRecord
scope :with_includes, -> { includes :services, :location, :manager }
end
@offices = Office.with_includes