我想按班级学生过滤家长电子邮件地址列表。
这是我的模型的简化:
Class District
has_many :schools
has_many :families
has_many :children, :through => :families
has_many :parents, :through => :families
has_many :enrollments, :through => :children
end
Class Enrollments
belongs_to :child
belongs_to :classroom
end
电子邮件地址与父记录相关联,我想通过一组教室 ID 过滤电子邮件。
我可以让它工作:
idees = [49, 50]
current_district = District.first
@emails = current_district.parents.includes(:family => { :children => { :enrollments => {:classroom => { :program => :location }}}}).where("family_id IN (?)", idees)
# Returns families with ID 49 and 50
但我无法让这样的事情发挥作用
idees = [49, 50]
current_district = District.first
@emails = current_district.parents.includes(:family => { :children => { :enrollments => {:classroom => { :program => :location }}}}).where("family.children.enrollments.classroom_id IN (?)", idees)
# Returns: PGError: ERROR: cross-database references are not implemented: family.children.enrollment.classroom_id
我做错了什么还是有另一种更好的方法来编写这个查询?