Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh ActiveRecord result

How to refresh ActiveRecord result in "rails way"? Example:

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

Is it possible to do something like stuff.refresh_data to re-execute query?

like image 968
Jonas Avatar asked Feb 25 '12 21:02

Jonas


People also ask

What does rails reload do?

Reloads the attributes of object(here @user) from the database. It always ensures object has latest data that is currently stored in database.

How do you refresh a console?

Simply type in the “reload!” command after making changes and the console will reload the session. The “reload!” command is limited in the sense that objects that were instantiated before the reload session will only have access to the initial code prior to any changes.


1 Answers

You can use reload. In your case you would write stuff.reload

Here is the documentation.

like image 51
Andreas Avatar answered Sep 19 '22 05:09

Andreas