Hi,
I have two models:
class Manufacturer < ActiveRecord::Base
has_many :models
end
class Model < ActiveRecord::Base
belongs_to :manufacturer
belongs_to :model
end
What I want to be able to do is find all manufacturers whose models belong to a given category:
manufacturers = Model.find(:all, :conditions=>["vehicle_category_id = 1"], :include => :manufacturer, :group => "manufacturer_id").map {|model| model.manufacturer }
But I want to be able to order the results by manufacturer name i.e. manufacturer.name
Do you know how I can do this?
UPDATE:
This works for me, but seems very inefficient, must be a better way:
manufacturers = (Model.find(:all, :conditions=>["vehicle_category_id = 1"], :include => :manufacturer, :group => "manufacturer_id").map {|model| model.manufacturer }).compact.sort{|x,y| x.name <=> y.name}