Are objects stored in session updated automatically?

If I lookup a user, and store that object in my session

      @user = User.find(:id)       session[:user] = @user

then the user record changes in the database in some way, then I try and reaccess that object

      @user = session{:user]       @first_name = @user.first_name

Is the field "first_name" the most updated or is it still the value originally stored in the object?

- Dave

Hi, if you update a session variable, you’re not updating the database as well. Thus, in your example, you’re simply modifying the object’s field, first_name, stored in session.

Good luck,

-Conrad

The object stored in the session is just a reference to the in-memory User object, it will not reflect changes to the database. Conventional RoR wisdom dictates that you should not store full objects in the session at all, but rather the id of the object which can then be used to lookup the object in the database as necessary.