Accessing entire current SESSION row - Not just DATA column

Hi,

I am in need to perform left join between my friends table and In built
sessions table:

LEFT JOIN sessions ON sessions.user_id=friendships.friend_id

To do this, I have altered sessions table to have user_id apart from
what i wud store in session data.

session[:user_id] points to user_id in Data Hash.
session.user_id throws me an error.(undefined method user_id)

How do i set this user_id for the session row when someone logs in? How
can I access session table? How will I know the current session id?

Regards,
Sandeep G

On 2/13/08, Sandeep G. [email protected] wrote:

How do i set this user_id for the session row when someone logs in? How
can I access session table? How will I know the current session id?

You can use session.model to get at the underlying session record.

You can even reopen CGI::Session::ActiveRecordStore::Session to add
associations if you like.

jeremy

Thanks Jeremy!
session.model worked fine for current sessions. I am able to set
user_ids for sessions henceforth.

Another issue is, Now that I have added user_id to sessions, I need to
set that for existing rows as well.I tried to do that with:

stored_sessions = CGI::Session::ActiveRecordStore::Session.find(:all)
stored_sessions.each do |stored_session|
id = Marshal.load( Base64.decode64( stored_session[‘data’] ) )
stored_session[‘user_id’] = id[:user_id]
stored_session.save
end

But save part does’nt work.
I tried something fancy like this:
id[‘model’].update_attribute(:user_id, id[:user_id])
Only to get syntax error…

What I am missing here?