Rails:在所有表中的日期时间列中递增 [英] Rails: increment in a datetime column in all tables

查看:16
本文介绍了Rails:在所有表中的日期时间列中递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 20 个表,每个表都有列 updated_at 我想更新所有表中的所有行,例如每一行的 updated_at 列应该增加 1 小时.

Let's say I have 20 tables and every table has column updated_at I want to update all the rows in all the tables such as every row's updated_at column should increase 1 hour.

如何避免更新活动记录对象我更愿意在每个表上运行 SQL 查询,而不是对一个表进行一个查询.

How can I do it with avoiding to update active records object I would prefer to run a SQL query instead on every table one query for one table.

推荐答案

只是为了帮助其他人,我是如何解决这个问题的

just to help others here is how was I able to get this solve

ActiveRecord::Base.connection.execute("UPDATE users SET created_at = created_at + INTERVAL '3600 seconds'")

这篇关于Rails:在所有表中的日期时间列中递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆