The other option is counter_cache and similar denormalizations. That's the approach I usually use.
Bryan On Thu, Sep 6, 2012 at 8:05 AM, Gert Thiel <[email protected]> wrote: > My app includes myriads of calculated columns. I prefer SQL views that > include these calculated columns so Rails / Hobo don't need to know about > that detail. > > Am Freitag, 17. August 2012 22:34:58 UTC+2 schrieb Mike: >> >> 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/-/EdNsvVYDslUJ. > > 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. -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. 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.
