gregbell/active_admin — pull request #1849 by azach (2013-01-09 03:14:46+00:00)
Title: Allow resource collections to be sorted by virtual columns

I have a use case where I'm generating a collection that includes a virtual SQL column. Everything works great, except when I want to add some ordering. This is because we include the table name in the order query by default. If we leave it out when the column name doesn't exist on the table, then it works fine. An example use case would be something like:

```ruby
class Product < ActiveRecord::Base
has_many :orders
end

class Order < ActiveRecord::Base
belongs_to :product
end

ActiveAdmin.register Product do
controller do
def scoped_collection
Product.select('*, count(orders.id) as total_ordered').joins(:orders).group('orders.product_id')
end

index do
column('Number of orders', :sortable => 'total_ordered') { |product| product.total_ordered }
end
end
```