Hello, Is it possible to order a result set by one of the values in an habtm relationship? If so, how can this be done? For example, I have a data set of providers. @levels = Level.find(:all) @pages, providers = paginate(:providers, :conditions => ["last_name LIKE ?", @initial+''%''], :order => "last_name, first_name") @providers = providers.collect { |provider| provider } In the model, providers has_and_belongs_to_many levels, and levels has_and_belongs_to_many providers. Is it possible, whether in the view or in the controller, to cause the query to sort itself by levels? So, it would display the providers associated within a given level, and then sort by whatever is in the controller. Currently, the view is like this: <% if @pages %> <% for provider in @providers %> (enter values for the provider in this area. I can get it to display values from the level by doing this:) <% for level in provider.levels do %><%= level.name.downcase %><% end %> <% end %> <% end %> Any thoughts would be most appreciated. Thanks. Jonathan -- 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 -~----------~----~----~----~------~----~------~--~---