活动记录 - 查找记录与今日前created_at [英] Active Record - Find records which were created_at before today

查看:105
本文介绍了活动记录 - 查找记录与今日前created_at的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的所有记录,其中created_at字段小于今天(日期)。 有什么样:

  MyTable.find_by_created_at(小于2.days.ago)
 

解决方案

基本的ActiveRecord(AR):

  MyModel.where([created_at<,2.days.ago])
 

AR与阿雷尔

  MyModel.where(MyModel.arel_table [:created_at] .LT(2.days.ago))
 

等同于previous,但使用此薄层超过阿雷尔:

  MyModel.where(为MyModel [:created_at]< 2.days.ago)
 

使用 squeel

  MyModel.where {created_at< 2天前 }
 

I want to get all records where the created_at field is less than today (a date). Is there anything like:

MyTable.find_by_created_at(< 2.days.ago)

解决方案

Basic ActiveRecord (AR):

MyModel.where(["created_at < ?", 2.days.ago])

AR with Arel:

MyModel.where(MyModel.arel_table[:created_at].lt(2.days.ago))

Equivalent to the previous, but using this thin layer over Arel:

MyModel.where(MyModel[:created_at] < 2.days.ago)

Using squeel:

MyModel.where { created_at < 2.days.ago }

这篇关于活动记录 - 查找记录与今日前created_at的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆