У меня есть 4 модели:жадная загрузка в гнездовой ассоциации
class Profile < ActiveRecord::Base
has_many :profile_profile_categories, dependent: :destroy
has_many :profile_categories, through: :profile_profile_categories
end
class ProfileCategory < ActiveRecord::Base
belongs_to :profile_subject
end
class ProfileSubject < ActiveRecord::Base
has_many :profile_categories, dependent: :destroy
end
class ProfileProfileCategory < ActiveRecord::Base
belongs_to :profile_category
belongs_to :profile
end
Как я могу загрузить профиль и нетерпеливый ProfileCategory нагрузки и ProfileSubject?
Profile.includes(profile_categories: :profile_subject)
не работает.
Gem пуля шоу следующее уведомление в браузере:
user: verrom N+1 Query detected ProfileSubject => [:profile_categories] Add to your finder: :includes => [:profile_categories]
А в логах сервера я могу видеть много запросов к таблице ProfileCategory как:
ProfileCategory Load (2.6ms) SELECT "profile_categories".* FROM "profile_categories" WHERE "profile_categories"."profile_subject_id" = $1 [["profile_subject_id", 4]]
Благодарность
он не работает. – verrom
Попробуйте этот раз ... – Mukesh
Это тоже не работает. – verrom