I have a schedule model hav开发者_开发知识库ing start time as date time and duration in minutes as integer.
Using named scope is there a way I can get the records having (start_time + duration) < current_time
?
You might implement what you asked for with SQL level date manipulation functions, like mysql's DATE_ADD:
scope :not_over, where('DATE_ADD(start_time, INTERVAL duration MINUTE) > UTC_TIMESTAMP()')
Though if performance is a consideration, you might want to precalculate an 'end_time' column and add an index on it.
精彩评论