モデルレベルで熱心にロードできるかどうか疑問に思います:
# country.rb
class Country < ActiveRecord::Base
has_many :country_days
def country_highlights
country_days.map { |country_day| country_day.shops }.flatten.uniq.map { |shop| shop.name }.join(", ")
end
end
# country_day.rb
class CountryDay < ActiveRecord::Base
belongs_to :country
has_many :country_day_shops
has_many :shops, :through => :country_day_shops
end
# shop.rb
class Shop < ActiveRecord::Base
end
.includes
ほとんどの場合、ポリモーフィックな関連付けのため、コントローラーで使用するのは困難です。コントローラーcountry_highlights
に追加する必要がないように、モデルレベルでメソッドを熱心にロードする方法はありますか?.includes