0
我有两个型号:如何使用超类中的属性对ActiveRecord结果进行排序?
class Manufacturer < ActiveRecord::Base
has_many :models
end
class Model < ActiveRecord::Base
belongs_to :manufacturer
belongs_to :model
end
我想做什么就能做的是找到所有的制造商,其型号属于某一类别:
manufacturers = Model.find(:all, :conditions=>["vehicle_category_id = 1"], :include => :manufacturer, :group => "manufacturer_id").map {|model| model.manufacturer }
但我希望能够订购结果按制造商名称即制造商。名称
你知道我该怎么做吗?
UPDATE:
这对我的作品,但似乎非常低效的,必须有更好的方式:
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}