sybind sybind - 3 months ago 11
Ruby Question

find all records where two conditions are true

I'm trying to find all records where two conditions are true. For example:

ruby-1.8.7-p302 > Person.all
=> #<Person name: "Jane", city: "Green Bay", state: "Wisconsin", single: true>
=> #<Person name: "Dick", city: "Madison", state: "Wisconsin", single: false>
=> #<Person name: "Tom", city: "Milwaukee", state: "Wisconsin", single: true>


I want to get the "Jane" and "Tom" records. I'm trying this, but it doesn't work:

Person.find_all_by_state("Wisconsin").find_all_by_single(true)

Answer

Person.where(:state => "Wisconsin", :single => true)