I have these models and I'm playing with meta_search to order it.
class Company < ActiveRecord::Base
has_many :delivers
has_many :estimates, :through => :deliver
end
class Estimate < ActiveRecord::Base
has_many :delivers, :dependent => :destroy
has_many :companies, :through => :delivers
end
class Deliver < ActiveRecord::Base
belongs_to :estimate
belongs_to :company
end
As you can see a company has many estimates and I need a filter to show companies in this order: from company who has the highest number of estimates to company that has the lowest number of estimates.
I'd like to have a sort link for it, something like:
= sort_link @search, :estimates_asc
I know that I can order in that way companies with this statement
Company.joins(:estimates).sort_by{|x| -x.estimates.size}
Thanks for helping me.