Use column accessor for updating an existing object instead of passing the new values...
Alexander Hartmaier [Mon, 2 Aug 2010 15:35:49 +0000 (17:35 +0200)]
This enables the column accessors to do additional work (for example with method modifiers)

Changes
lib/Catalyst/Controller/DBIC/API.pm

diff --git a/Changes b/Changes
index 17a46d8..c995424 100644 (file)
--- 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
 
index acc8722..061dbb3 100644 (file)
@@ -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);