activerecord-hackery / meta_search

Object-based searching (and more) for simply creating search forms. Not currently maintained.
http://erniemiller.org/2013/11/17/anyone-interested-in-activerecord-hackery/
MIT License
903 stars 140 forks source link

Sort Virtual Attribute (or for this purpose associated records count) #101

Open marclipovsky opened 12 years ago

marclipovsky commented 12 years ago

I'd like to be able to sort the associated records count. For example:

# form.rb
class Form
    has_many :references

    def reference_count
        self.references.count
    end
end

# reference.rb
class Reference
    belongs_to :form
end

#my view
= sort_link @search, :reference_count, 'References'

Is this possible? Or being able to sort the count directly without the virtual attribute.

Thanks!