I am changing an existing query to avoid SQL injection.The query goes like this
People.select('DISTINCT people_id') .where(person_id: id) .where("position_id IN (#{approval_id.join(', ')})") .where('ended_on IS NULL or ended_on > ?', Date.today) where approval_id is array with value [1, 2, 3, 4]
when I am changing the query line 3
.where("position_id IN (#{approval_id.join(', ')})") to .where("position_id IN ?", approval_id) It is not working. what is going wrong? as approval_id is an array I can pass it directly to an IN.
()around the query param, so(?). IIRC you can also just writewhere(position_id: approval_id). Unrelated, but I would name the variable to reflect it's a collection,approval_ids.