I have Products and Reviews; Product :has_many reviews, Review :belongs_to product. Review.find_by_product_id(5) returns only one Review because it is incorrectly translated into (MySQL) "SELECT * FROM reviews WHERE (reviews.`product_id` = 5) LIMIT 1". So >> Product.find(5).reviews.count => 6 >> Review.find_by_product_id(5) => #<Review:0x2b1cefb2a1d8 @attributes=...> How can I tell Rails that Review.find_by_product_id should return a collection and not a single result? -- Gioele -- 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 -~----------~----~----~----~------~----~------~--~---
Gioele Barabucci wrote:> How can I tell Rails that Review.find_by_product_id should return a > collection and not a single result?Answering to myself: use Review.find_all_by_product_id instead. -- Gioele -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Gioele, Gioele Barabucci wrote:> Review.find_by_product_id(5) returns only one Review because it is > incorrectly translated into (MySQL) "SELECT * FROM reviews WHERE > (reviews.`product_id` = 5) LIMIT 1". So > > >> Product.find(5).reviews.count > => 6 > > >> Review.find_by_product_id(5) > => #<Review:0x2b1cefb2a1d8 @attributes=...> > > How can I tell Rails that Review.find_by_product_id should return a > collection and not a single result?Review.find_all_by_product_id(5) If you wanted to limit the result set you''d need to move to the :conditions => [,,,] syntax and use :limit hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---