1 package Apache::MVC::Model::CDBI;
2 use base qw(Apache::MVC::Model::Base Class::DBI);
3 use Lingua::EN::Inflect::Number qw(to_PL);
4 use Class::DBI::AsForm;
5 use Class::DBI::FromCGI;
8 sub description { "A poorly defined class" }
10 sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns }
14 return $self->retrieve(shift @{$r->{args}});
19 # Has-many methods; XXX this is a hack
21 grep { exists $r->{config}{ok_tables}{$_} }
23 keys %{shift->__hasa_list}
26 sub do_edit :Exported {
28 my $h = CGI::Untaint->new(%{$r->{params}});
29 my ($obj) = @{$self->objects};
31 # We have something to edit
32 $obj->update_from_cgi($h);
33 warn "Updating an object ($obj) with ".Dumper($h); use Data::Dumper;
35 $obj = $self->create_from_cgi($h);
37 if (my %errors = $obj->cgi_update_errors) {
38 # Set it up as it was:
39 warn "There were errors: ".Dumper(\%errors)."\n";
40 $r->{template_args}{cgi_params} = \%params;
41 $r->{template_args}{errors} = \%errors;
42 $r->{template} = "edit";
44 $r->{template} = "view";
46 $r->objects([ $obj ]);
49 sub delete :Exported {
51 $_->SUPER::delete for @{ $r->objects };
52 $r->objects([ $self->retrieve_all ]);
53 $r->{template} = "list";
57 my ($self, $child) = @_;
58 $child->autoupdate(1);
59 $child->columns( Stringify => qw/ name / );