3

중첩 된 다형성 연결을 열심히로드하려고합니다. 솔루션을 찾을 수없는 것 같습니다. 수중첩 된 다형성 연결을 열망하는 방법

ActiveRecord::EagerLoadPolymorphicError - Can not eagerly load the polymorphic association :ownable 

방법 :

Post.includes(comments: :ownable).to_a 

을하지만이 오류를 던지고 :

class Post 
    has_many :comments 
end 

class Comment 
    belongs_to :ownable, polymorphic: true 
end 

class User 
    has_many :comments, as: :ownable 
end 

그리고 여기에 내가 할 노력하고있어입니다 : 여기

내 모델 설정입니다 이 중첩 된 다형성 연관을 열망합니까? 모든 포스트 has_many 코멘트

+0

의 중복 가능성 [열망로드 다형성 (http://stackoverflow.com/questions/16123492/eager-load-polymorphic) – Makoto

답변

2

우선도 설정해야합니다 : 레일 테이블이 소유 가능한 찾을 수 없기 때문에

class Post 
     has_many :comments, as: :ownable 
    end 

수 소유 가능한> = 심지어이를 변경 한 후, 당신은 여전히 ​​같은 오류가 발생합니다.

주위 여기에 게시 작업이 Eager load polymorphic

관련 문제