Re: force re-retrieve from database

[prev] [thread] [next] [Date index for 2005/06/14]

From: Charles Bailey
Subject: Re: force re-retrieve from database
Date: 15:03 on 14 Jun 2005
--On June 14, 2005 4:48:13 PM +0200 Hartmaier Alexander 
<Alexander.Hartmaier@xxxxxxxxx.xx> wrote:

> Ok I like the idea.
> I looked in Class/DBI.pm for the update method to figure out how to delete
> attributes from an object but didn't find what I wanted.
> These lines seem to do what I want but I don't want to use internals that
> might change in a new version:
>
>
> $self->call_trigger('after_update', discard_columns => \@changed_cols);
>
>         # delete columns that changed (in case adding to DB modifies them
> again)
>         $self->_attribute_delete(@changed_cols);
>         delete $self->{__Changed};
>
> What does the first line do?

The first line calls any triggers you may have registered.
The second removes any attributes that were changed by the update, so 
future attempts to access them will cause them to be reread from the 
database (in case a SQL trigger modified them, for instance).
The third is just internal housekeeping to make sure that future calls to 
update() won't continue to rewrite the attributes we just finished writing.

> Do I have to take care of '$self->{__Changed}' to not break something
> else?

Not of you use a trigger; all of its activity will occur at the point of 
the call_triggers() line above, and update will clean up after you as usual.

> I THINK that '$self->_attribute_delete(('mycolname'));' would be enough
> but I want an official ACK from the cdbi developers/maintainers...

I'm 100% non-official, but this is the documented (and previously 
officially blessed on the list) way to delete an attribute without calling 
CDBI triggers and the like.  You should be able to count on support for

    $self->_attribute_delete($self->find_column('mycolname'))

(Note that the column arguments to _attribute_* are Class::DBI::Column 
objects.  At the moment they stringify to the lowercase column name and are 
used as keys into a hashref, so you can use the name directly, but I don't 
think that's guaranteed to remain viable.

--
Regards,
Charles Bailey  < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania

force re-retrieve from database
Hartmaier Alexander 14:35 on 13 Jun 2005

Re: force re-retrieve from database
Charles Bailey 18:55 on 13 Jun 2005

Re: force re-retrieve from database
Hartmaier Alexander 08:44 on 14 Jun 2005

Re: force re-retrieve from database
Charles Bailey 13:47 on 14 Jun 2005

Re: force re-retrieve from database
Hartmaier Alexander 14:48 on 14 Jun 2005

Re: force re-retrieve from database
Charles Bailey 15:03 on 14 Jun 2005

RE: force re-retrieve from database
Zhuang Li 17:28 on 14 Jun 2005

Re: force re-retrieve from database
Hartmaier Alexander 08:44 on 15 Jun 2005

Generated at 16:37 on 28 Jul 2005 by mariachi v0.52