我有这样的一个表:凡符合条件
Calendar
- date
- description
- userid
而且我想获得用户通过它用户标识的特定月份的所有事件。
所以我知道,要得到所有事件的用户ID是:
Calendar.where(userid: params[:id])
我试过(正如我在一些岗位中看到的已经在这里)
Calendar.where(userid: params[:id]).where("date ~= ?", '%2016-12%')
因此,这应该给我所有事件从2016年的第12个月,而是我有:
ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: date ~= unknown
LINE 1: ...endars" WHERE "calendars"."userid" = $1 AND (date ~= '%2016-...
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我做错了什么?
是您的日期列日期时间类型? –
是的,为什么? – Difender