Rails:所有表的datetime列中均不显示 [英] Rails: Increament in a datetime column in all tables
本文介绍了Rails:所有表的datetime列中均不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有20个表,每个表都有一列update_at,我想更新所有表中的所有行,例如每行的updated_at字段应增加1小时。如何避免更新活动记录对象呢?我宁愿在每个表上运行一个sql查询,而不是在一个表上查询一个表。
Lets 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 field should increase 1 hour. 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:所有表的datetime列中均不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文