Russ Bradberry
Russ Bradberry

Reputation: 10865

How Do I Create an 'OR' Condition Using the ActiveRecord Model

Given the following code which creates an and condition, how do I make it create an or condition instead?

Country.first(:conditions=>{:media_code=>country_code, :code=>country_code})

Upvotes: 1

Views: 84

Answers (1)

Tatjana N.
Tatjana N.

Reputation: 6225

You can do that with array style conditions:

Country.first(:conditions => ["media_code = :code or code = :code", {:code => country_code}])

Upvotes: 4

Related Questions