在我的Rails 5应用程序中,我从查询中收到此错误,但我不知道如何修复它。
PG::SyntaxError: ERROR: subquery has too many columns
我的控制器:
def index
@canvases = current_user.get_voted Canvas
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.friend_ids, owner_type: "User").or(PublicActivity::Activity.order("created_at desc").where(recipient_id: current_user.id)).or(PublicActivity::Activity.order("created_at desc").where("key = ? AND recipient_id in (?)", "canvas_product.create", @canvases)).paginate page: params[:page], per_page: 30
end
错误在此查询中的某处:
(PublicActivity::Activity.order("created_at desc").where("key = ? AND recipient_id in (?)", "canvas_product.create", @canvases))
答案 0 :(得分:1)
看起来@canvases
是一组实际的画布,也许Rails并没有正确地将它们解释为ID ...
您可以将其转换为这样的ID:
where("key = ? AND recipient_id in (?)", "canvas_product.create", @canvases.map(&:id))
或者,您可以在关联上使用pluck
来选择您需要的ID,例如:
@canvas_ids = current_user.get_voted(Canvas).pluck(:id)
(虽然这取决于get_voted
的编写方式)