2
레일을 죽여하지 않습니다 : 4.1.2, 루비 2.1.1레일 4.1.2 열망로드는 N + 1 개 쿼리
을 내가 commentable
및 has_many :comments
module Commentable
extend ActiveSupport::Concern
included do
has_many :comments, :as => :commentable
end
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true, :touch => true
belongs_to :user
#other codes....
end
인 Article
클래스를 가지고 기사를 표시 할 때 모든 관련 정보를로드하고 싶습니다.
@item = Article.includes(:tags, {:comments => :user}).where(id: params[:id]).first
이며 태그 및 주석 객체를 미리로드합니다.
그러나 comments
을 렌더링하면 설명 개체와 사용자 개체가 다시로드됩니다. 로그에서
= render @item.comments
:
레일 버전을 지정하십시오. –
@ Зелёный updated, thanks – fengd
덕분에, 나는 같은 문제 (열망하는 다형성 레코드로드). +1 –