]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI/DFV.pm
fixes to fixes to changes to fixes
[maypole.git] / lib / Maypole / Model / CDBI / DFV.pm
index a16fa30e3adea337dba6239ee6ec8b8df98a424f..7848759d610a72bc97711b175af01bd196d41704 100644 (file)
@@ -152,10 +152,6 @@ sub do_edit : Exported {
   if (ref $errors) {
     # pass errors to template
     $r->template_args->{errors} = $errors;
-    foreach my $error (keys %$errors) {
-      $r->template_args->{errors}{ucfirst($error)} = $errors->{$error}
-    }
-
     # Set it up as it was:
     $r->template_args->{cgi_params} = $r->params;
     $r->template("edit");
@@ -183,8 +179,14 @@ sub _do_update {
     }
   }
 
-  my $this_class_params = { map { $_ => $r->{params}{$_} }  $class->columns  };
-  delete $this_class_params->{route_id};
+
+  my $this_class_params = {};
+  foreach my $param ( $class->columns ) {
+    next if ($param eq $class->columns('Primary'));
+    my $value = $r->params->{$param};
+    next unless (defined $value);
+    $this_class_params->{$param} = ( $value eq '' ) ?  undef : $value;
+  }
 
   # update or make other related (must_have, might_have, has_many  etc )
   unless ($errors) {
@@ -219,7 +221,15 @@ sub _do_update {
 sub _do_create {
   my ($class,$r) = @_;
   my $errors;
-  my $this_class_params = { map { $_ => $r->{params}{$_} }  $class->columns  };
+
+  my $this_class_params = {};
+  foreach my $param ( $class->columns ) {
+    next if ($param eq $class->columns('Primary'));
+    my $value = $r->params->{$param};
+    next unless (defined $value);
+    $this_class_params->{$param} = ( $value eq '' ) ?  undef : $value;
+  }
+
   my $obj;
 
   my $dfv_results = Data::FormValidator->check($r->{params}, $class->dfv_profile);