Let''s say I have class Student < ActiveRecord::Base has_many :classes_students has_many :classes, :through => :classes_students end I want the list of classes for each student to be sorted by the class title. I could get an array containing the classes and then sort it. But, I would like for the database to do the work. Is there some combination of :include and :order that would cause rails to ask for a sorted list? I know this does not work: has_many :classes, :through => :classes_students, :order => ''title'' Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
User.find(:all, :include => [:profile], :order => ''profiles.name ASC'') Seems to work for me ... not sure that it should, but it does. Chris http://www.dummied.org On 3/29/07, Rick <rschumeyer-EkmVulN54Sk@public.gmane.org> wrote:> > > Let''s say I have > > class Student < ActiveRecord::Base > has_many :classes_students > has_many :classes, :through => :classes_students > end > > I want the list of classes for each student to be sorted by the class > title. > I could get an array containing the classes and then sort it. But, I > would like for the database to do the work. > > Is there some combination of :include and :order that would cause > rails to ask for a sorted list? > > I know this does not work: > has_many :classes, :through => :classes_students, :order => ''title'' > > Any ideas? > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > I know this does not work: > > has_many :classes, :through => :classes_students, :order => ''title''What do you mean this does not work? It works for me. Does it not sort it the way you want? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---