나는이 세 가지 다른 테이블의 다형성 연관이 하나 개의 모델 : 당신이 볼 수 있듯이가져 오는 행
class User < ActiveRecord::Base
belongs_to :authenticatable, :polymorphic => true
# == Schema Information
#
# Table name: employees
#
# id :integer(4) not null, primary key
# ...
# school_id :integer(4)
class Guardian < ActiveRecord::Base
has_one :user, :as => :authenticatable
belongs_to :school
# == Schema Information
#
# Table name: guardians
#
# id :integer(4) not null, primary key
# ...
# school_id :integer(4)
class Guardian < ActiveRecord::Base
has_one :user, :as => :authenticatable
belongs_to :school
# == Schema Information
#
# Table name: students
#
# id :integer(4) not null, primary key
# ...
# school_id :integer(4)
class Student < ActiveRecord::Base
has_one :user, :as => :authenticatable
belongs_to :school
는 지난 3 개 모델은 "학교"모델에 속하고, 따라서를 school_id
이라는 열이 있어야합니다. 나는 user
에서 모든 해당 행을 검색하여 해당 인증 가능한 school_id가 어떤 값과 같도록하려고합니다. 명확히하기 위해, 나는 같은 것을 할 싶습니다
User.joins(:authenticatable).where(:school_id => some_value)
을 그대로, 즉 마지막 주에
ActiveRecord::EagerLoadPolymorphicError
가 발생합니다, 내가 제안 몇 가지 문서를 찾기 위해 관리 그 다형성 연관이 같은 작업을해야에 포함하여 :
: 나는이 작업을 수행 할 경우User.find(:all, :include => :authenticatable) (This works)
User.find(...)
이 Array
을 반환하고 해당 클래스에 where 메서드가 정의되어 있지 않기 때문에 레일이 끊어집니다.
다른 옵션을 시도했지만 원하는 것을 성취 할 수있는 방법을 찾지 못했습니다. 너 나 좀 도와 줄 수있어? 감사!
http://exackoverflow.com/questions/2079867/activerecordeagerloadpolymorphicerror-can-not-eagerly-load-the-polymorphic-ass – mark