Where clause for a has_many

I have two models, History and SalesOrder, which are setup like this:

class History < ActiveRecord::Base

belongs_to :sales_order

end

class SalesOrder < ActiveRecord::Base

has_many :histories
has_many :latest_history,
:class_name => “History”,
:order => “id desc”

end

Is it possible to use a where clause when finding SalesOrders that is
based on History? For example:

orders = SalesOrder.find(:all, :order => ‘latest_history asc’)

Is that kind of thing even possible with Active Record?

I think you want to pass has_many a block with your conditions…

Read about it here:

b