On Thu, Apr 12, 2007 at 12:21:03PM -0500, stephen joseph butler wrote:
> THE PROBLEM:
> 
> I've been using Storable::dclone to make a clone of a Row before
> updating it so that I can later find the differences (I'm using
> DBIx::Class::HTMLWidget, so get_dirty_columns isn't available to me).
> Here's what my code looks like (using Catalyst):
> 
> sub save {
>  my ( $self, $c, $id, $widget_result ) = @_;
> 
>  my $new_obj = $c->model( 'DB::Object' )->find( $id );
>  my $old_obj = dclone( $new_obj );

my $old_obj = $new_obj->result_source->resultset->new({ $new_obj->get_columns 
});

> 
>  $new_obj->populate_from_widget( $widget_result );
> 
>  my %diff;
>  foreach ($old_obj->result_source->columns) {
>    next if $old_obj->get_column( $_ ) eq $new_obj->get_column( $_ );
> 
>    $diff{ $_ } = {
>      old => $old_obj->$_,
>      new => $new_obj->$_
>    };
>  }
> 
>  # render %diff with TT
> }

That way you'll get the result source etc. already there and you've got the
object. The other thing to do is to overload update and have that populate
the diff for you.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
Shadowcat Systems Ltd.   Contact mst (at) shadowcatsystems.co.uk for a quote
                                          http://www.shadowcatsystems.co.uk/ 

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to