Skip to content
Advertisement

Append additional conditions to a query

I have a query where I need to add several conditions as an OR clause, because I want to use LIKE, so I can not use IN instead.

So how can I add multiple OR from an array?

The SQL should look like this:

where ‘a’, ‘b’, ‘c’ is from an array.

Advertisement

Answer

From the Rails API docs, the .or conditional query should be chained after a .where method.

The full answer:

The same can be achieved without a gem (assuming Sequel.like is coming from this gem) in “vanilla” Rails.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement