I have an usual pagination in rails. But I am trying to sort by a property which is not in the same table on the database. (I have an Entry class which has a region_id. Then I got a Region class with id and name. Now I would like to sort the Entries in my Pagination with the name of the region.) If I use a collection I have to load the whole bunch and therefore this is not an option. Do I need to do a find_by_sql? Or do I miss anything? thanks h. -- 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 -~----------~----~----~----~------~----~------~--~---
huli wrote:> > > I have an usual pagination in rails. But I am trying to sort by a > property which is not in the same table on the database. (I have an > Entry class which has a region_id. Then I got a Region class with id and > name. Now I would like to sort the Entries in my Pagination with the > name of the region.) > > If I use a collection I have to load the whole bunch and therefore this > is not an option. Do I need to do a find_by_sql? Or do I miss anything? >You can pass all the options you would usually pass to find to paginate, so in this case you could use :joins => "INNER JOIN regions on regions.id = region_id" and then you can :order => ''regions.name'' Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Fred wrote:> huli wrote: >> >> >> I have an usual pagination in rails. But I am trying to sort by a >> property which is not in the same table on the database. (I have an >> Entry class which has a region_id. Then I got a Region class with id and >> name. Now I would like to sort the Entries in my Pagination with the >> name of the region.) >> >> If I use a collection I have to load the whole bunch and therefore this >> is not an option. Do I need to do a find_by_sql? Or do I miss anything? >> > You can pass all the options you would usually pass to find to paginate, > so in this case you could use :joins => "INNER JOIN regions on > regions.id = region_id" and then you can :order => ''regions.name'' > > FredCool thats it! Thanks a lot! h. -- 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 -~----------~----~----~----~------~----~------~--~---