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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 On Sep 7, 2006, at 5:12 PM, lundie wrote:> > 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! > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks for the help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---