gpt4 book ai didi

ruby-on-rails - 我可以将 PostgreSQL 的 "Special Date/Time Inputs"与 ActiveRecord 一起使用吗?

转载 作者:行者123 更新时间:2023-11-29 13:26:32 24 4
gpt4 key购买 nike

PostgreSQL 支持多个 "Special Date/Time Inputs" , 它在执行时解释的字符串。例如,'now' 表示“当前事务的开始时间”,'infinity' 表示“晚于所有其他时间戳”。

ActiveRecord 似乎不理解这些 - 例如,SomeRecord.update!(updated_at: DateTime.current) 有效,但是 SomeRecord.update!(updated_at: 'now') 尝试使用 NULL 执行 UPDATE 查询。

这些特殊字符串在 Rails fixtures 中确实有效,因为它们直接进入数据库。但是有没有办法将它们与实例化模型一起使用?

最佳答案

您可以使用 raw_write_attribute(:updated_at, 'now') 设置值

关于ruby-on-rails - 我可以将 PostgreSQL 的 "Special Date/Time Inputs"与 ActiveRecord 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32874877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com