1

我想按班级学生过滤家长电子邮件地址列表。

这是我的模型的简化:

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

我做错了什么还是有另一种更好的方法来编写这个查询?

4

1 回答 1

0

下面的行是问题所在。

where("family.children.enrollments.classroom_id IN (?)", idees)

将其更改为:

where("enrollments.classroom_id IN (?)", idees)
于 2012-07-27T19:32:23.650 回答