在我的Rails 5應用程序中,我收到來自查詢的這個錯誤,但我不知道如何解決它。Rails - PG :: SyntaxError:錯誤:子查詢有太多列
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))
在猜測......'@ canvases'是一組實際的畫布,也許Rails沒有將這些解釋爲正確的ID ...嘗試將其改爲:'where(「key =?和()中的recipient_id,「canvas_product.create」,@ canvases.map(&:id))' - 如果這樣的話,那麼你就知道它就是這樣的 –
就是這樣!謝謝!我應該這樣做,以限制@canvases只是在查詢之前的id(效率更高)?謝謝! – yellowreign
我會創建一個答案並加上:) –