morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

just a quick DBIx::Class question:

What is the proper way to check if an object is dirty?

Currently I simply do

if( $obj->get_dirty_columns ) { # $obj is dirty ...
which works, however in my particular case I don't really care about which columns are dirty - only if there is at least one of them dirty, so I am throwing information away that DBIx::Class worked so hard to obtain...

Is that nevertheless the proper way to check?

Many thanks!

Replies are listed 'Best First'.
Re: checking for dirtyness in DBix::Class
by Your Mother (Archbishop) on Dec 27, 2010 at 15:00 UTC

    You're doing too much work, I expect. DBIx::Class::Row->update contains-

    my %to_update = $self->get_dirty_columns or return $self;

    So update is already no-op if nothing has changed (it can be forced to update individual columns anyway with make_column_dirty). If you really want to know if something/anything has changed there is also the method is_changed (and is_column_changed to boot).

      Thanks mother.

      is_changed is exactly what I wanted.