From f59ec6e803f30a07c3d726c40fa0cffc2e669142 Mon Sep 17 00:00:00 2001
From: Aaron Trevena <aaron.trevena@gmail.com>
Date: Fri, 3 Nov 2006 11:51:16 +0000
Subject: [PATCH] fixed fixes to bugs in DFV model when updating and creating
 object

git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@546 48953598-375a-da11-a14b-00016c27c3ee
---
 lib/Maypole/Model/CDBI/DFV.pm | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/Maypole/Model/CDBI/DFV.pm b/lib/Maypole/Model/CDBI/DFV.pm
index a16fa30..ded183f 100644
--- a/lib/Maypole/Model/CDBI/DFV.pm
+++ b/lib/Maypole/Model/CDBI/DFV.pm
@@ -183,8 +183,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 +225,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);
-- 
2.39.5