刷新ActiveRecord结果

时间:2012-02-25 21:17:15

标签: ruby-on-rails activerecord

如何以“rails方式”刷新ActiveRecord结果?例如:

stuff = Stuff.find(:id)
a = stuff.x   # a = 3
(at this time field value in database stuff.x changed to 7 )
a = stuff.x   # a = 3 but I need here 7

是否可以执行stuff.refresh_data之类的操作来重新执行查询?

1 个答案:

答案 0 :(得分:27)

您可以使用reload。在你的情况下,你会写stuff.reload

这是documentation