我收到这个参数:param[:date] = '2017-03-04'
我的数据库中创建的列是具有以下格式的created_at:'2017-01-01 09:21:23'
当我执行此查询时
Mymodel.where(created_at: params[:date])
这将返回一个空数组,这是合乎逻辑的,因为时间还未到。
我需要所有与参数日期对应的行。
我该如何做?在这种情况下,时间不重要,我只需要日期。
我正在使用Postgres作为数据库。
我需要选择例如某一特定日期的全部销售,并且用于搜索的列是created_at。
where("created_at::date = ?, seller_id = ?", params[:date], params[:seller_id])
。或者你可以使用链式调用where
,我认为这样更加简洁:where("created_at::date = ?", params[:date]).where(seller_id: params[:seller_id])
。 - Adam Lassek