代码之家  ›  专栏  ›  技术社区  ›  martins

` event.where(“开始时间>=”?“,datetime.now)`不起作用

  •  0
  • martins  · 技术社区  · 6 年前

    我正在将对重复事件的支持添加到我的rails应用程序中。 其中一个功能是 recurring_event.delete_this_and_following

    应用程序/模型/重复事件.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_time.to_s => "2018-10-23 11:24:59 UTC"

    1 回复  |  直到 6 年前
        1
  •  0
  •   martins    6 年前

    这很奇怪。可能是斯普林没能重新装弹什么的。 我今天重新启动了我的机器,现在它可以工作了:

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

    无论如何,谢谢你的建议!:-)