Re: Let me adjust my question (was: A strange problem I have...)

[prev] [thread] [next] [Date index for 2004/12/16]

From: William McKee
Subject: Re: Let me adjust my question (was: A strange problem I have...)
Date: 19:21 on 16 Dec 2004
On Mon, Dec 13, 2004 at 11:23:14AM -0500, Perrin Harkins wrote:
> Get rid of the object (set it to undef) and fetch it again.

I too have run into this need to reload an object as well as the problem
of receiving old data, esp. with the object index which loads an
existing object if it is already in use. Currently, I've used the
solution which Perrin suggested.

It seems like a function that could combine the undef and retrieve
operations as well as update the object index would be useful. Since DBI
must be subclassed, this function could be added to your subclass. This
would provide another possible solution for people having troubles with
objects staying in the index (albeit still a workaround for poorly
written code).

Perhaps something along the lines of the following code would work:

    sub refresh {
      my $obj = shift;
      my @cols = $obj->primary_columns;

      # Uncomment the following line if you are having problems with
      # data not refreshing or wish to have multiple distinct copies of
      # the same object in memory
      #$obj->remove_from_object_index();

      undef $obj;
      $obj = __PACKAGE__->retrieve(@cols);
    }

It'd be nice to be able to extract the package name from the object
before undefining it so that this function can be declared in the parent
package or perhaps even in CDBI itself. However, I'm unclear on how to
get that information.

Also, I'm not sure whether calling remove_from_object_index on an object
in a mod_perl environment would mean that the object never gets
reindexed. From what I can tell of reading the code, the next retrieval
should regenerate the object in the hash.


William

        -- 
        Knowmad Services Inc.
http://www.knowmad.com

(message missing)

Re: Let me adjust my question (was: A strange problem I have...)
William McKee 19:21 on 16 Dec 2004

Generated at 09:04 on 20 Dec 2004 by mariachi v0.52