0

as the title suggests I am trying to query my model. I am trying to query it based of two conditions. I came across this question, though similar it doesn't quite answer my question.

I have tried the following method but it only works if the lists are populated.

school.classes.where.not('"classes"."highest_achiever_id" NOT IN (?) OR "classes"."room_id"' NOT IN (?), [1,2,3,4], [1,2,3,4])

The above query is what I am using to retrieve all classes that meet my conditions, my only problem is the case where the list being passed is empty this query seems to return empty results.

aDev
  • 43
  • 9
  • 3
    In your question you are doing `WHERE NOT (column_name NOT IN (1,2,3))`. Is that intentional? Because that could just be a regular `WHERE column_name IN (1,2,3)`. – rPat Oct 12 '21 at 16:49
  • No wonder I was having issues with my query it should have been `WHERE (column_name NOT IN (1,2,3) )` The 2 NOTs were negating each other. – aDev Oct 12 '21 at 16:51
  • i think you could apply the De Morgan's law: `!(A OR B) = !A AND !B` – Lam Phan Oct 13 '21 at 03:33

0 Answers0