return;
}
+
my $errors;
if ($obj) {
($obj,$errors) = $class->_do_update($r,$obj);
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");
}
}
- 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;
+ }
# update or make other related (must_have, might_have, has_many etc )
unless ($errors) {
# get related object if it exists
my $rel_meta = $class->related_meta('r',$accssr);
if (!$rel_meta) {
- $class->_carp("No relationship for $accssr in " . ref($class));
+ $r->warn("[_do_update] No relationship for $accssr in " . ref($class));
next;
}
}
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);
my $created = [];
my $rel_meta = $self->related_meta('r',$accssr);
if (!$rel_meta) {
- $self->_carp("No relationship for $accssr in " . ref($self));
+ $self->_carp("[_create_related] No relationship for $accssr in " . ref($self));
return;
}