]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI/DFV.pm
fixed bug in DFV model when updating object
[maypole.git] / lib / Maypole / Model / CDBI / DFV.pm
index 5c7a1273a39c0c57b0757ad89b82398068c70526..a16fa30e3adea337dba6239ee6ec8b8df98a424f 100644 (file)
@@ -96,6 +96,21 @@ sub adopt {
     }
 }
 
+=head2 check_params
+
+  Checks parameters against the DFV profile for the class, returns the results
+  of DFV's check.
+
+  my $dfv_results = __PACKAGE__->check_params($r->params);
+
+=cut
+
+sub check_params {
+  my ($class,$params) = @_;
+  return Data::FormValidator->check($params, $class->dfv_profile);
+}
+
+
 =head1 Action Methods
 
 Action methods are methods that are accessed through web (or other public) interface.
@@ -125,7 +140,7 @@ sub do_edit : Exported {
     return;
   }
 
-  my $required_cols = $class->required_columns;
+
   my $errors;
   if ($obj) {
     ($obj,$errors) = $class->_do_update($r,$obj);
@@ -169,6 +184,7 @@ sub _do_update {
   }
 
   my $this_class_params = { map { $_ => $r->{params}{$_} }  $class->columns  };
+  delete $this_class_params->{route_id};
 
   # update or make other related (must_have, might_have, has_many  etc )
   unless ($errors) {
@@ -176,7 +192,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};
@@ -197,7 +214,6 @@ sub _do_update {
   }
 
   return ($obj,$errors);
-
 }
 
 sub _do_create {
@@ -242,7 +258,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};