[Dbix-class] How to find updated fields

RA Jones ra.jones at dpw.clara.co.uk
Fri Mar 23 10:31:15 GMT 2007


Guillermo Roditi wrote:
> I think you could possibly implement this as a component that wraps
> update, delete, or insert and the use get_dirty_columns et al.
> 
> eg
> 
> sub update{
>    my ( $self, $upd, @rest ) = @_;
>    my %cols = $obj->get_dirty_columns;
>    %cols = (%cols, %$upd) if( ref $upd );
>    warn( "Updated: ". join(", ", keys %cols)  );
>    $self->next::method($upd, @rest);
> }

Well I cannot get this to work. I'm using catalyst and formbuilder, and 
doing the update like:

$form->update($fields);	

That works OK, but if I try to capture the result of the action:

my $r = $form->update($fields);	

and dump $r to file, get_dirty_columns does not exist, the closest is 
_dirty_columns which is an undefined hashref:

$VAR1 = bless( {
   'related_resultsets' => {},
   '_orig_ident' => undef,
   '_dirty_columns' => {},
   etc,

Am I missing something obvious here?

> On 3/22/07, RA Jones <ra.jones at dpw.clara.co.uk> wrote:
>> Rob Kinyon wrote:
>> > On 3/22/07, RA Jones <ra.jones at dpw.clara.co.uk> wrote:
>> >> In my applications I frequently record in a log file which fields
>> >> were updated by which users. Is there an easy way in DBIC to find
>> >> out which fields got updated during an update() or
>> >> update_or_insert() action? Thanks.
>> >
>> > Look for the get_dirty_columns() method on the Row object.
>> Thanks, I had just scanned the DBIC::Row manual, and managed to miss
>> that one - is_changed() looked promising, but it appears to be only for
>> uncommitted changes.
>> -- 
-- 
Richard Jones
Leeds, UK
ra.jones(at)dpw.clara.co.uk



More information about the Dbix-class mailing list