【发布时间】:2019-03-20 22:11:08
【问题描述】:
我正在向我的 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"
【问题讨论】:
-
start_time的值是多少?start_time列的数据类型是什么? -
start_time => 2018 年 10 月 23 日星期二 11:24:59 UTC +00:00
-
` t.datetime "start_time"`
-
试试
event.recurring_events.where("recurring_events.start_time >= ?", start_time).destroy_all
标签: ruby-on-rails activerecord