Hi, There are 3 models: A has_many :Cs B has_many :Cs C belongs_to A and B I got a single object of A and an array of B objects. How can I get all Cs that have a_id equal to object A.id *and* b_id that belongs to an object in Bs array? Regards --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Jul 2008, at 16:56, szimek wrote:> > Hi, > > There are 3 models: > A has_many :Cs > B has_many :Cs > C belongs_to A and B > > I got a single object of A and an array of B objects. How can I get > all Cs that have a_id equal to object A.id *and* b_id that belongs to > an object in Bs array? >C.find_all_by_a_id_and_b_id(A.id, [some_objects]) should work Fred> Regards > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 4 Lip, 18:20, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 Jul 2008, at 16:56,szimekwrote: > > > > > Hi, > > > There are 3 models: > > A has_many :Cs > > B has_many :Cs > > C belongs_to A and B > > > I got a single object of A and an array of B objects. How can I get > > all Cs that have a_id equal to object A.id *and* b_id that belongs to > > an object in Bs array? > > C.find_all_by_a_id_and_b_id(A.id, [some_objects]) > > should work > > Fred > > > > > RegardsThanks! I had no idea you can pass an array of AR objects to find_by_something_id. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---