开发者

Using named scope

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜