I have a companies table and a products table companies --> id,name,address,owner,country ... products --> id, company_id,name, photo In my controller I have @companies=Company.find(:all,:include=>''products'',:conditions=>["products.name LIKE ''%tool% and company.country=''spain'' "]) in my view i can show all the companies that have the product <% for company in @companies %> <%= company.name %> <%end%> and I can show all the products found <% for product in @companies.products %> <%= product.name %> <%end%> That''s all OK. But now I want to research the list of products under a new criteria using the previous records found. @companies.products.find(:all,:conditions=>[''date>2007-07-05'']) But I get ALL the product with criteria date>2007-07-05 and not just those who meet both criterias (date criteria and name like ''%tool%'') based on the records found previously. How can I do that? --~--~---------~--~----~------------~-------~--~----~ 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, 2007/8/2, cfingerh <cfingerh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> That''s all OK. But now I want to research the list of products under a > new criteria using the previous records found. > @companies.products.find(:all,:conditions=>[''date>2007-07-05'']) > > But I get ALL the product with criteria date>2007-07-05 and not just > those who meet both criterias (date criteria and name like ''%tool%'') > based on the records found previously. How can I do that?You could use select on @companies.products: @companies.products.select {|product| product.date > Time.mktime(2007, 7, 5) } Lutz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you very much. And if I want to get the cheapest product with those restrictions? @companies.products.select {|product| product.date > Time.mktime(2007, 7, 5) } But I want to get the product with the cheapest price ----> product.price --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---