thank_you
thank_you

Reputation: 11107

Where Clause with OR in Rails

How do I write a where clause where I have a where argument that can take multiple options. For example,

User.where(name: "Jason" OR name: "Bob")

Although I know that isn't the correct syntax, what is?

Upvotes: 0

Views: 254

Answers (2)

tobinjim
tobinjim

Reputation: 1852

I'm always late to the party...

friends = User.where(:name => ["Jason", "Bob"])

(Rails 4.0.0)

Upvotes: 0

Chowlett
Chowlett

Reputation: 46667

While I don't have a console to hand to check, I'm pretty sure it's:

User.where(name: ["Jason", "Bob"])

Upvotes: 3

Related Questions