]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI/DFV.pm
removed C3 and no longer require it
[maypole.git] / lib / Maypole / Model / CDBI / DFV.pm
index eb2bf20668834329b18f692042fa03ae13c931f5..5aa0e9ab85cc37aa592800a620449a3c0ff73c16 100644 (file)
@@ -35,7 +35,6 @@ of CGI::Untaint. For teh win!!
 
 =cut
 
-use Class::C3;
 use Data::FormValidator;
 use Data::Dumper;
 
@@ -140,6 +139,7 @@ sub do_edit : Exported {
     return;
   }
 
+
   my $errors;
   if ($obj) {
     ($obj,$errors) = $class->_do_update($r,$obj);
@@ -151,10 +151,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");
@@ -182,7 +178,22 @@ sub _do_update {
     }
   }
 
-  my $this_class_params = { map { $_ => $r->{params}{$_} }  $class->columns  };
+
+  my $this_class_params = {};
+
+
+  # NG changes start here.
+  # Code below fails to handle multi col PKs
+  my @pks = $class->columns('Primary');
+
+  foreach my $param ( $class->columns ) {
+    # next if ($param eq $class->columns('Primary'));
+    next if grep {/^${param}$/} @pks;
+
+    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) {
@@ -190,7 +201,8 @@ sub _do_update {
       # get related object if it exists
       my $rel_meta = $class->related_meta('r',$accssr);
       if (!$rel_meta) {
-       $class->_croak("No relationship for $accssr in " . ref($class));
+       $r->warn("[_do_update] No relationship for $accssr in " . ref($class));
+       next;
       }
 
       my $rel_type  = $rel_meta->{name};
@@ -211,13 +223,20 @@ sub _do_update {
   }
 
   return ($obj,$errors);
-
 }
 
 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);
@@ -256,7 +275,8 @@ sub _create_related {
   my $created = [];
   my $rel_meta = $self->related_meta('r',$accssr);
   if (!$rel_meta) {
-    $self->_croak("No relationship for $accssr in " . ref($self));
+    $self->_carp("[_create_related] No relationship for $accssr in " . ref($self));
+    return;
   }
 
   my $rel_type  = $rel_meta->{name};