这个查询有些奇怪,我无法解决
我有一个有很多评论的帖子模型。我想获取过去 24 小时内的评论
p=Post.first
p.comments.where("(:t - comments.created_at) <= :d", t: Time.now, d: 1.day)
Comment Load (1.0ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = 76 AND "comments"."commentable_type" = 'Post' AND (('2013-03-07 06:08:09.045488' - comments.created_at) <= 86400) ORDER BY created_at DESC
然而,这并没有给我任何东西,即使
p.comments
是
[#<Comment id: 132, title: "", comment: "comment", commentable_id: 76, commentable_type: "Post", user_id: 1, created_at: "2013-03-07 05:43:37", updated_at: "2013-03-07 05:43:37">]
这是为什么?