我想按学生班级筛选家长电子邮件地址列表。
以下是我的模型的简化:
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我做错了什么?或者有没有另一种更好的方法来编写这个查询?
发布于 2012-07-28 03:32:24
下面这行就是问题所在。
where("family.children.enrollments.classroom_id IN (?)", idees)将其更改为:
where("enrollments.classroom_id IN (?)", idees)https://stackoverflow.com/questions/11692957
复制相似问题