Ruby Activerecord IN clause

From ยง3.3.3 Subset Conditions of the Rails Guides:

If you want to find records using the IN expression you can pass an
array to the conditions hash:

Customer.where(orders_count: [1,3,5])

This code will generate SQL like this:

SELECT * FROM customers WHERE
(customers.orders_count IN (1,3,5))

You can also use the arel syntax:

Client.where(Client.arel_table[:order_count].in([1,3,5]))

will generate the same SQL.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)