On Sun, Sep 13, 2009 at 2:10 PM, Wyatt Baldwin
<[email protected]> wrote:
>
> On Sep 13, 4:19 am, pydon <[email protected]> wrote:
>> Hopefully reading this correctly.
>>
>> So I cannot store a whole object in a session but instead should just
>> store a reference to it?
>
> The session only stores an object reference anyway. I think what's
> being suggested is to store a (primary) key in the session for easy DB
> lookup.
>
> I think which approach you choose depends on your app. I have an app
> where I store a reference to the SA user object in the session and
> this works fine for me. The trick is that you have to do `Session.merge
> (session['user'])` (or something to that effect) at the beginning of
> each request.

Oh, here you go, it even has that pattern in the documentation.

http://www.sqlalchemy.org/docs/05/session.html#merging

"""A web application stores mapped entities [i.e., a user object]
within an HTTP session object. When each request starts up, the
serialized data can be merged into the session, so that the original
entity may be safely shared among requests and threads."""

I would still disassociate (expunge) the object from the SQLAlchmey
session before putting it in the Beaker session in the first place
though.

-- 
Mike Orr <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to