Re: Can you $Class->update_all() ?

[prev] [thread] [next] [Date index for 2004/07/19]

From: Charles Bailey
Subject: Re: Can you $Class->update_all() ?
Date: 18:13 on 19 Jul 2004
--On Monday, July 19, 2004 6:53 PM +0100 Ian McDonald-ONLINE 
<ian.mcdonald@xxx.xx.xx> wrote:
>
> For my application, I'd like to be able to issue a single command which
> will run update on every Class::DBI object which needs it, and does not
> generate SQL for those which do not. This will probably be impemented as
> a method of a UnitOfWork class which knows which table classes exist and
> will go through them all calling a $Class->update_all() method.
>
> My questions are:
> * Is something like this possible with Class::DBI?
> * How?
> * Will it only run SQL commands for the Class::DBI objects which really
> have changed?

Your best bet might be to override set() in your application base class in 
order to keep track of objects whose attributes change.  This should catch 
all user-level changes; if you want to catch internal changes as well, you 
could override _attribute_set() instead.

The class's update_all() method could then iterate over the set of changed 
objects and update each one.  If you expect changes to be reverted 
frequently, update_all() might check that each $obj->is_changed; this will 
be false if the user discarded the changes to the object.

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

Can you $Class->update_all() ?
Ian McDonald-ONLINE 17:53 on 19 Jul 2004

Re: Can you $Class->update_all() ?
Perrin Harkins 18:01 on 19 Jul 2004

Re: Can you $Class->update_all() ?
Charles Bailey 18:13 on 19 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52