Sorting on a calculated column in table-plus is quite annoying.  I have 
searched for answers - and I haven't been able to find one....has anyone 
else?

So here is my solution, not DRY, but it works.  It is based on the idea 
that someone suggested for creating a view - but I wanted to define it in 
the app itself.
 ---

In the model, where you have defined the variable like

> def mycolumn

  one_column - two_column

end 


you can add a named_scope and inject sql like

> named_scope :specialscope, {

:select => "mymodels.*, (mymodels.one_column - mymodels.two_column) as 
> mycolumn"

  } 


and then in your controller you just add the named scope, and table-plus 
sorting options....

>   def index 
>     hobo_index Mymodel.specialscope.apply_scopes(:search    => 
> [params[:search], :blah1, :blah2], :order_by  => 
> parse_sort_param(:mycolumn, :name))
>   end  


magic! it works!

 what do you guys think?  is this really bad for performance etc?  

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/hobousers/-/z_j_Dg0JuMcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to