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!