[Dbix-class] Serialize::Storable and dclone
Matt S Trout
dbix-class at trout.me.uk
Tue May 8 12:12:13 GMT 2007
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/
More information about the Dbix-class
mailing list