[CDBI] Re: Refresh variables for Object?

Dan Rowles d.rowles at outcometechnologies.com
Fri Dec 15 10:46:45 GMT 2006


How about:-

sub reload {
     my $this = shift;
     my %pk = map { $_ => 1 } $this->primary_columns;
     my @discard = grep { !$pk{$_} } $this->all_columns;
     $this->_attribute_delete(@discard);
     return $this;
}

Now, next time you try to access any fields in your object, Class::DBI 
will go back to the database for you to get their latest values (see the 
"_flesh()" method.

Dan




Edward J. Sabol wrote:
> Graham Melcher wrote:
>> I'd like to clear the 'essential' and any other cache'd values for an
>> object such that they must be re-queried from the database when
>> accessed.  I've looked over the cpan docs and the wiki, but I can't find
>> that sort of function.
> 
> If I needed to do that, I guess I would do something like the following:
> 
> $artist->remove_from_object_index();
> $artist->discard_changes() unless $artist->autoupdate;
> $artist = Music::Artist->retrieve($artist->id);
> 
> Obviously, you can skip the discard_changes() if you know you definitely
> haven't made any changes to the object or if you are using autoupdate mode.
> It's only real purpose is to avoid the warning message you get when an
> altered, uncommitted CDBI object is DESTROY'ed.
> 
> It should be simple enough to devise a generic "refresh" method which does
> the above steps (and handles MCPKs!) that you can put in your CDBI base
> class. If you do come up with a generic method like that, please add it to
> the wiki!
> 
> Hope this helps,
> Ed
> 
> _______________________________________________
> ClassDBI mailing list
> ClassDBI at lists.digitalcraftsmen.net
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

-- 
Dan Rowles
CTO
Outcome Technologies

_________________________________

t: +44 (0)207 656 2460
f: +44 (0)709 230 6588
m: +44 (0)798 076 8143
e: d.rowles at outcometechnologies.com
w: http://www.outcometechnologies.com
BUPA House
15-19 Bloomsbury Way
London WC1A 2BA
_________________________________

***This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. If you receive this message in error, please return it to the
sender.***



More information about the ClassDBI mailing list