This question is an exact duplicate of:
- Selecting all Records if Record has any of the ID's from Array 1 answer
I am having trouble finding the right syntax and operator to check if a record has the same ID of any of the ID's stored in an Array. Is there a has any?
function or similar?
@problem = Remedy.where(["LOWER(\"remedyName\") LIKE?", "%#{params[:searchremedy]}%".downcase]).pluck(:id)
@pretreatments = Treatment.joins(:remedies_treatment).where(:remedies_treatment_remedy_id == @problem)
I have updated the code to:
ids = Remedy.where(["LOWER(\"remedyName\") LIKE?", "%#{params[:searchremedy]}%".downcase]).pluck(:id)
@pretreatments = Treatment.joins(:remedies_treatments).where(remedies_treatments: { remedy_id: @problem })
However the error I am getting now is:
SELECT "treatments".* FROM "treatments" INNER JOIN "remedies_treatments" ON "remedies_treatments"."treatment_id" = "treatments"."id" WHERE "remedies_treatment"."remedy_id" IS NULL
Completed 500 Internal Server Error in 157ms (ActiveRecord: 17.0ms)
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: missing FROM-clause entry for table "remedies_treatment"
LINE 1: ...atments"."treatment_id" = "treatments"."id" WHERE "remedies_...
^
: SELECT "treatments".* FROM "treatments" INNER JOIN "remedies_treatments" ON "remedies_treatments"."treatment_id" = "treatments"."id" WHERE "remedies_treatment"."remedy_id" IS NULL):
app/controllers/treatments_controller.rb:116:in `index'
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "remedies_treatment"
LINE 1: ...atments"."treatment_id" = "treatments"."id" WHERE "remedies_...
^
: SELECT "treatments".* FROM "treatments" INNER JOIN "remedies_treatments" ON "remedies_treatments"."treatment_id" = "treatments"."id" WHERE "remedies_treatment"."remedy_id" IS NULL
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'