Forum: Ruby on Rails :include and conditions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
28c7ef5ffd77ddcaf495aa389103b764?d=identicon&s=25 Jason (Guest)
on 2007-04-04 22:36
What is wrong with the following:

@sales_orders = SalesOrder.find(:all, :include => [:histories, :routes],
:order => ' 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 => " asc"

   has_many :histories_status,
            :order => "route_id"

   has_one  :latest_history,
            :class_name => "History",
            :order => "id desc"


class History < ActiveRecord::Base

   belongs_to :user
   belongs_to :route
   belongs_to :sales_order


class Route < ActiveRecord::Base
  has_many :histories
  has_and_belongs_to_many :users

This topic is locked and can not be replied to.