gpt4 book ai didi

ruby-on-rails-3 - 为什么 update_attribute 不更改我的时间戳列

转载 作者:行者123 更新时间:2023-11-29 12:38:23 25 4
gpt4 key购买 nike

我有一个带有时间戳列的模型,queued_at。

为什么 update_attribute(:queued_at, Time.now) 不写入数据库?这只是偶尔发生。这是一个经常更新的属性。 update_column 似乎一直有效。

我在 postgres 中使用 rails 3.2.12。

rails 3.1.11不存在该问题

这些项目展示了“问题”:

  1. https://github.com/johnnaegle/scratch/tree/feature/rails_3.2.12
  2. https://github.com/johnnaegle/scratch/tree/feature/rails_3.1.11

最佳答案

看起来 active_record 足够聪明,知道正在更新的值是否相同或足够接近(在时间戳的情况下),它将避免 SQL 写入 - 节省性能。我已经成功地通过在 update_attribute 调用之后“触摸”相关对象的模型来强制写入 updated_at 字段

foo.update_attribute :last_status, status
foo.touch
## log entry
## UPDATE `foo` SET `updated_at` = '2013-07-25 19:56:36' WHERE `foo`.`id` = 55

关于ruby-on-rails-3 - 为什么 update_attribute 不更改我的时间戳列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14987821/

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