[英]Writing the following sql in active record / arel DB agnostic way
I got the following sql expression 我得到以下SQL表达式
g.date > CURRENT_DATE + INTERVAL '1' day * t.notice_days
g.date> CURRENT_DATE + INTERVAL'1'天* t.notice_days
it works on postgres and as raw sql via my app, Is there an elegant Active Record / AREL way to write the same expression? 它可以在postgres上使用,也可以通过我的应用作为原始sql使用,是否有一种优雅的Active Record / AREL方式可以编写相同的表达式?
Assuming you can get the Integer version of t.notice_days
and G
is a model you should just be able to do: 假设您可以获取
t.notice_days
的Integer版本,并且G
是一个模型,您应该可以执行以下操作:
future_time = t.notice_days.days.from_now
g.where("data > ?", future_time)
also you can set future_time as Time.now + t.notice_days.days
您也可以将future_time设置为
Time.now + t.notice_days.days
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.