I have a table which contains a column "discussion_duration" where I am storing certain times in seconds (6 hours = 21600). I would like to sort this table by 'created_at' + 'discussion_duration'.
I can add created_at and discussion_duration in ruby and it returns a date. However since the parameters in the rails .order() is raw sql, I'm not sure how to add these two fields then sort by the output.
Any help would be much appreciated.
edit: Actually this is probably what you're looking for. You'll need to use your database specific date/time functions to do it and here's a mysql example.
.order('TIMESTAMPADD(SECOND, discussion_duration, created_at)')
created_at + INTERVAL discussion_duration SECOND DESC'
fridgerator 2012-04-05 21:43
.order
something more complex. Is ordering it by created_at at the DB level and then by something more complex in Ruby code (or all of the ordering in code) acceptable to you - MrDanA 2012-04-04 17:42