用>查询(大于)返回记录> =(大于或等于)

时间:2012-12-08 08:22:45

标签: ruby-on-rails ruby-on-rails-3

有人可以解释为什么以下查询:

> modified_after = DateTime.parse "2012-12-06T17:40:36+00:00"
> Contact.unscoped.where("updated_at > :time OR deleted_at > :time", {:time => modified_after})

还会返回updated_at等于modified_after的记录:

Contact Load (0.4ms)  SELECT "contacts".* FROM "contacts" WHERE (updated_at > '2012-12-06 17:40:36' OR deleted_at > '2012-12-06 17:40:36') => [
#<Contact id: 28, first_name: "John", last_name: "A", deleted_at: nil, created_at: "2012-12-06 17:40:36", updated_at: "2012-12-06 17:40:36", email: nil, notes: nil>, 
#<Contact id: 29, first_name: "Mark", last_name: "B", deleted_at: nil, created_at: "2012-12-06 17:40:36", updated_at: "2012-12-06 17:40:36", email: nil, notes: nil>,
 #<Contact id: 30, first_name: "Michael", last_name: "C", deleted_at: nil, created_at: "2012-12-06 17:40:36", updated_at: "2012-12-06 17:40:36", email: nil, notes: nil>
]

1 个答案:

答案 0 :(得分:2)

可能是那些时间比查询时间大几毫秒。你在运行什么版本的Rails?查看此错误,看看它是否相关:https://github.com/rails/rails/issues/7385