]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Apache/MVC/Model/CDBI.pm
Make untainting, editing, and other things work.
[maypole.git] / lib / Apache / MVC / Model / CDBI.pm
index 88ba3da1334cd3383057cb69345f214614d5447a..695e1cbd7dec1fe0e6e6f9ed33863113df0b2c90 100644 (file)
@@ -1,5 +1,6 @@
 package Apache::MVC::Model::CDBI;
 use base qw(Apache::MVC::Model::Base Class::DBI);
+use Lingua::EN::Inflect::Number qw(to_PL);
 use Class::DBI::AsForm;
 use Class::DBI::FromCGI;
 use CGI::Untaint;
@@ -13,10 +14,19 @@ sub get_objects {
     return $self->retrieve(shift @{$r->{args}});
 }
 
+sub related {
+    my ($self, $r) = @_;
+    # Has-many methods; XXX this is a hack
+    map {to_PL($_)} 
+    grep { exists $r->{config}{ok_tables}{$_} }
+    map {$_->table}
+    keys %{shift->__hasa_list || {}}
+}
+
 sub do_edit :Exported {
     my ($self, $r) = @_;
     my $h = CGI::Untaint->new(%{$r->{params}});
-    my ($obj) = @{$self->objects};
+    my ($obj) = @{$r->objects};
     if ($obj) {
         # We have something to edit
         $obj->update_from_cgi($h);