What is wrong with the following:
@sales_orders = SalesOrder.find(:all, :include => [:histories, :routes],
:order => ''routes.name ASC'')
That should give me a list of all sales orders sorted by route_id, which
comes through the histories table. It doesn''t. They are somewhat
sorted by route, but not perfectly so. What am I doing wrong? Or is
there a find_by_sql phrase I can use here?
Here''s my models:
class SalesOrder < ActiveRecord::Base
has_many :histories
has_many :routes,
:through => :histories,
:order => "routes.name asc"
has_many :histories_status,
:order => "route_id"
has_one :latest_history,
:class_name => "History",
:order => "id desc"
end
class History < ActiveRecord::Base
belongs_to :user
belongs_to :route
belongs_to :sales_order
end
class Route < ActiveRecord::Base
has_many :histories
has_and_belongs_to_many :users
end
Thanks!
--
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
-~----------~----~----~----~------~----~------~--~---