I have a model called Person that has_one Address. Person has fields like first_name and last_name; Address has postal_code, state, and so on.
I know how to use finders to find all people with a certain name; that’s Person.find_by_last_name("Smith"). But how do I find all people where:
- their first_name is “Bob”; and
- their last_name is “Smith”; and
- who have addresses with a city of ‘Foobar’; and
- who have addresses with a postal_code of ‘12345’
When you’re looking for exact values, you can pass a hash of the values you’d like to match to
where. Each referenced model is its own nested hash, as in the example below: