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)')