I''m having trouble trying to join on multiple tables. In this example,
I want to do fetch of companies in a specified category and location.
The pagination code is using the will_paginate plugin. Any pointers?
Do I need to resort to a find_by_sql?
@category = Category.find(params[:category_id])
@location = Location.find(params[:location_id])
#Need to join on location id too, how?
@companies = @category.companies.paginate :all, :per_page =>
10, :page => params[:page]
Thanks,
Tommy
--~--~---------~--~----~------------~-------~--~----~
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 Tommy, There is a will_paginate group: http://groups.google.com/group/will_paginate Ask your question there, please. Thanks, - Mislav --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can you use a dynamic, attribute-based finder method with your has_many declaration? Or use an association extension if Rails doesn''t create it automatically. Like this: @category.companies.find_by_location(@location) This method won''t be terribly fast though since you are performing 3-4 queries. I would consider a specialized query method like "Company.find_by_category_and_location(cat_id, loc_id)". mike wheels wrote:> @category = Category.find(params[:category_id]) > @location = Location.find(params[:location_id]) > #Need to join on location id too, how? > @companies = @category.companies.paginate :all, :per_page => > 10, :page => params[:page] >-- 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 -~----------~----~----~----~------~----~------~--~---