I’ve just started using the .where method, and I’m a little bit confused about how to fully utilize it.
I’d like to do something like:
@books = Book.where(:author_id => 1 || 2)
clearly I know that doesn’t work, but I’m trying to demonstrate that I want some extra logic here. some “or” “and” “does not equal” etc.
Any ideas for where I can research this? I was looking in the rails API but I didnt see anything that was that helpful.
Thanks!
1 || 2won’t work because that expression is evaluated before the function call (it evaluates to 1, so it should be equivalent toBook.where(:author_id => 1). I would do:The generated SQL would be
WHERE author_id IN (1, 2).