I have a page where i go through all categories, and show the latest 3 games for each one. Right now i include those games when i fetch the categories in the controller: @categories = Category.find :all, :include => [:online_games] Is there a way to limit those games here to the amount that i want? It seems a bit inefficient to get all games per category here, and limit those in the view. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter wrote:> I have a page where i go through all categories, and show the latest 3 > games for each one. Right now i include those games when i fetch the > categories in the controller: > > @categories = Category.find :all, :include => [:online_games] > > Is there a way to limit those games here to the amount that i want? It > seems a bit inefficient to get all games per category here, and limit > those in the view.Why would not :limit => 3 work? -- 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 -~----------~----~----~----~------~----~------~--~---
because that would limit the categories to 3, not the games. On Mar 17, 4:08 pm, James Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Peter wrote: > > I have a page where i go through all categories, and show the latest 3 > > games for each one. Right now i include those games when i fetch the > > categories in the controller: > > > @categories = Category.find :all, :include => [:online_games] > > > Is there a way to limit those games here to the amount that i want? It > > seems a bit inefficient to get all games per category here, and limit > > those in the view. > > Why would not :limit => 3 work? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Peter wrote:> because that would limit the categories to 3, not the games. > > On Mar 17, 4:08 pm, James Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>more than what you are asking, you can make it the default :limit option when eager loading associations. i searched for ''eager loading associations ruby rails'' in google: http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html in this page, search for ''limit''. you can add a :limit => n number to the declaration in the model (has_many .. :limit => ) or whatever as the default limitation for the association you want to query. hope it helps out :) shai -- 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 -~----------~----~----~----~------~----~------~--~---