在ActiveRecord::Base.connection.execute('UPDATE ...')
被解雇或需要重新加载后,ActiveRecord模型是否自行更新?
答案 0 :(得分:1)
不,每次你直接对连接做一些事情,你都是独立的,需要确保一切都是同步的。
c = Car.create! name: "Car 1"
c.name # => "Car 1"
Car.connection.execute "UPDATE cars SET name = 'Car 2' WHERE id = 1"
c.name # => "Car 1"
c.reload.name # => "Car 2"