开发者

Using named scope

开发者 https://www.devze.com 2023-02-20 23:32 出处:网络
I have a schedule model hav开发者_开发知识库ing start time as date time and duration in minutes as integer.

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

精彩评论

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