I have this:>> a=RpPart.find(:all)=> [#<RpPart id: 1, product_id: 1, ...">, #<RpPart id: 2, product_id: 1 ...">, #<RpPart id: 3, product_id: 2, ...>] How can I select only de rp_parts with product_id=1? Is there something like @repair_ticket = RepairTicket.find(????) ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> I have this: >> >>>> a=RpPart.find(:all) >> => [#<RpPart id: 1, product_id: 1, ...">, #<RpPart id: 2, product_id: 1 >> ...">, #<RpPart id: 3, product_id: 2, ...>] > > a = RpPart.find(:all, :conditions => "product_id=1") > > If that is ever going to be dynamic do it like this: > > pid = 123 > a = RpPart.find(:all, :conditions => ["product_id = ?", pid]) > > -philipThank you very much. It has been very helpful. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can also use: part = RpPart.find_by_product_id(2) If there can be more than one with the same product_id: part = RpPart.find_all_by_product_id(2) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Or Product.find(2).rp_parts if it''s associated like that. On Jan 10, 2008 9:10 AM, Jeremy Weiskotten <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > You can also use: > > part = RpPart.find_by_product_id(2) > > If there can be more than one with the same product_id: > > part = RpPart.find_all_by_product_id(2) > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> Or Product.find(2).rp_parts if it''s associated like that. > > On Jan 10, 2008 9:10 AM, Jeremy Weiskotten > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> >> > >> > > > -- > Ryan Bigg > http://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.This way you''ll *probably* execute more SQL queries. One to fetch the product and another to fetch its rp_parts. Something to consider, especially if performance is a concern. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I have this: > >>> a=RpPart.find(:all) > => [#<RpPart id: 1, product_id: 1, ...">, #<RpPart id: 2, product_id: 1 > ...">, #<RpPart id: 3, product_id: 2, ...>]a = RpPart.find(:all, :conditions => "product_id=1") If that is ever going to be dynamic do it like this: pid = 123 a = RpPart.find(:all, :conditions => ["product_id = ?", pid]) -philip> > > How can I select only de rp_parts with product_id=1? > Is there something like @repair_ticket = RepairTicket.find(????) ? > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---