“ Event.where(“ start_time> =?”,DateTime.now)”不起作用

时间:2018-10-16 11:26:17

标签: ruby-on-rails activerecord

我在Rails应用程序中添加了对重复事件的支持。 功能之一是recurring_event.delete_this_and_following

app / models / recurring_event.rb

   16 class RecurringEvent < ApplicationRecord
   17   belongs_to :event

   32   def delete_this_and_following
   33     event.recurring_events.where("start_time >= ?", start_time).destroy_all
   34   end

不幸的是,这给了我这个错误:

(byebug) event.recurring_events.where("start_time >= ?", start_time).size
*** ActiveRecord::StatementInvalid Exception: PG::InFailedSqlTransaction: 
ERROR:  current transaction is aborted, commands ignored until end 
of transaction block
: SELECT COUNT(*) FROM "recurring_events" 
WHERE "recurring_events"."event_id" = $1 AND 
(start_time >= '2018-10-23 10:42:50.281315')

nil

start_date的格式错误吗? start_time.to_s => "2018-10-23 11:24:59 UTC"

1 个答案:

答案 0 :(得分:0)

这很奇怪。可能是弹簧无法重新加载或发生了什么。 我今天重启了机器,现在可以正常工作了:

event.recurring_events.where("start_time >= ?", start_time).destroy_all

仍然感谢您的建议! :-)