Topic: Find where with or?

I am trying to find data based on 2 columns where one column equals something or the other column equals something. Basically something like this:

.where(:bid_date => @firstdate..@lastdate or :sold_date => @firstdate..@lastdate, :estimator_id => @estid, :gcontractor_id => @gcid, :awarded_amount => @bidwonoptions)

Is there away short of doing it all in sql?

Re: Find where with or?

It's not rails 3 way I think, but you can try:
.where("(bid_date BETWEEN ? AND ? OR sold_date BETWEEN ? AND ?) AND estimator_id = ? AND gcontractor_id = ? AND awarded_amount = ?", @firstdate, @lastdate, @firstdate, @lastdate, @estid, @gcid, @bidwonoptions)
Also you can try multiple where functions(Account.where(:id => 1).or.where(:id => 2)). I haven't used it, but you can read about it.

Re: Find where with or?

Thank you for the reply. That is good to know how to do your first suggestion, could not figure out the that syntax. I did get this working using Squeel, may not be the best way but it works