Help with find()

Hi,

I have a customers model with a one to many relationship to an
addresses model, to allow customers to have multiple addresses.

I need to be able to search for customers using their different address
specifications. What is the best way to accomplish with? I currently am
going in a round about way, doing a find on the addresses model, and
then looing through all of the addresses and extracting each one of the
customers using address.customer, and placing them into an array.

Is there a one step solution to this problem, ie a find statement that
will produce all customers with (for example) a city of toronto?

Thanks for the help!

It sound like you want to find Customer objects so perform the find
on Customer and include the addresses table. This allows you to add
conditions that reference addresses columns.

You could do something like this:
Customer.find(:all, :conditions => ["addresses.city=?",
'Toronto'], :include => :addresses)

Aaron

Thanks for the help!