Re: [CDBI] Re: uniqueness of objects in memory??

[prev] [thread] [next] [Date index for 2005/10/25]

From: Phil Mitchell
Subject: Re: [CDBI] Re: uniqueness of objects in memory??
Date: 06:08 on 25 Oct 2005
On 10/24/05, Perrin Harkins <perrin@xxxx.xxx> wrote:
> On Mon, 2005-10-24 at 16:34 -0700, Phil Mitchell wrote:
> > For sanity's sake, here's the sequence:
> >
> > User logs in and User object is saved to session
> > User has a prefs object
> > User wants to edit prefs
> > Prefs object is retrieved from db
> > Prefs object is updated
> > User->prefs is not refreshed
>
> Okay, this is the sort of thing I meant by the sequence of actions.
> This makes it clear what the issue is.
>
> The object index works by keeping a hash of weak references to all
> objects in the current process as they are loaded from the database.  It
> does this in the constructor.  Things you put in the session are never
> loaded from the database again, so they don't get registered in the
> object index.  The session just runs the object through a
> Storable::thaw, without calling the constructor.
>
> I would advise you to never put CDBI objects in a session, or otherwise
> serialize them with Storable.  Besides the fact that they don't call the
> CDBI constructor, you are also probably going to overwrite things in
> your database and lose changes.  When you load the User object from the
> session, it has the same values it had when you put it in there, even if
> the database has been updated since then.  If you have some code that
> manipulates a User object and saves it to the db but not to the session,
> you'll lose that change when you get the User from the session next
> time.  It gets even more complex when you have has_a relationships,
> since the parent object keeps a reference internally to the other one,
> and so both will get serialized and stored in the session, compounding
> the chances for lost updates.
>
> If you want to keep things in your session, stick to simple values, like
> the ID of your User object.
>

Okay, thanks Perrin and thanks to all who helped me resolve this!
Thanks for sticking with the long thread. I feel a little chagrined,
as I suspect this is well-known, but summarized the whole thread on
CDBI wiki so it wasn't all in vain!

http://cdbi.dcmanaged.com/wiki/Common_problems

cheers,

Phil




> - Perrin
>
>


--
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
2People Blog: http://2-people.blogspot.com/
2People site: http://www.2people.org

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

(message missing)

[CDBI] uniqueness of objects in memory??
Phil Mitchell 03:32 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Perrin Harkins 16:12 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Phil Mitchell 17:42 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Perrin Harkins 18:41 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Christopher H. Laco 18:53 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Phil Mitchell 19:43 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
William Ross 19:50 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Phil Mitchell 19:35 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Perrin Harkins 19:52 on 24 Oct 2005

[CDBI] Re: uniqueness of objects in memory??
Edward J. Sabol 19:47 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Perrin Harkins 19:54 on 24 Oct 2005

[CDBI] Re: uniqueness of objects in memory??
Edward J. Sabol 20:03 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 20:18 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Christopher H. Laco 19:46 on 24 Oct 2005

Re: [CDBI] uniqueness of objects in memory??
Christopher H. Laco 19:56 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Michael Peters 20:23 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 20:31 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Bill Moseley 20:46 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 21:30 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 22:07 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Perrin Harkins 22:13 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 23:34 on 24 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Rod McChesney 03:15 on 25 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 03:48 on 25 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Perrin Harkins 04:18 on 25 Oct 2005

Re: [CDBI] Re: uniqueness of objects in memory??
Phil Mitchell 06:08 on 25 Oct 2005

Generated at 14:18 on 27 Oct 2005 by mariachi v0.52