0
我想查詢2表,憑據和集成。我想檢索每個憑據記錄WHERE user_id == current_user.id
。我也想檢索每個集成記錄WHERE name == "Twitter"
。Rails加入多個條件的查詢
正下方運行,並輸出[[4, "Twitter"][3,"YouTube"]]
Credential.joins(:integration).where(user_id: current_user.id).pluck(:id, :name)
查詢直接下面的查詢應該運行併產生[4, "Twitter"]
而是它產生一個錯誤。
Credential.joins(:integration).where(user_id: current_user.id).where(integration: {name: 'Twitter'}).pluck(:id, :name)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "integration"
LINE 1: ...ration_id" WHERE "credentials"."user_id" = $1 AND "integrati...
最終,我試圖將我在其他代碼中使用的集成列入白名單。如果我在連接參數.joins(:integrations)
中使用複數,Rails拒絕查詢。
「哪裏(整合:{..})'工作,與複數? – Iceman
哇。這工作!謝謝!如果你發佈解決方案,我會給你點數! – HashRocketSyntax
很高興工作,發佈了一個答案 – Iceman