From: Alexander Hartmaier Date: Mon, 2 Aug 2010 15:35:49 +0000 (+0200) Subject: Use column accessor for updating an existing object instead of passing the new values... X-Git-Tag: 2.002002~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=3b12c2cd6893d11ca090fbd599782f0a27979922 Use column accessor for updating an existing object instead of passing the new values to update This enables the column accessors to do additional work (for example with method modifiers) --- diff --git a/Changes b/Changes index 17a46d8..c995424 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for Catalyst-Controller-DBIC-API: {{ $dist->version }} {{ $NEXT }} - Fixed search for related columns overwriting existing params in generate_column_parameters +- Use column accessor for updating an existing object instead of passing the new values to update. + This enables the column accessors to do additional work (for example with method modifiers). 2.002001 2010-04-01 01:41:11 Europe/Berlin diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index acc8722..061dbb3 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -734,9 +734,10 @@ sub update_object_from_params { $self->update_object_relation($c, $object, delete $params->{$key}, $key); } + $object->$key($value); } - $object->update($params); + $object->update(); } =method_protected update_object_relation @@ -751,7 +752,11 @@ sub update_object_relation my $row = $object->find_related($relation, {} , {}); if ($row) { - $row->update($related_params); + foreach my $key (keys %$related_params) { + my $value = $related_params->{$key}; + $row->$key($value); + } + $row->update(); } else { $object->create_related($relation, $related_params);