X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI.pm;h=2a79850805008930c4f461e734c5bcb5a15d0161;hb=5c199c0e9cd05a00bfc04d9688982979a41f3ee8;hp=71e1a49f69e9a3457c8434112ce0776a490bda90;hpb=094460849c1f2c4ec4ca0a153da2f5039eeedd40;p=maypole.git diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 71e1a49..2a79850 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -26,12 +26,7 @@ modules. 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 || {}} + return keys %{$self->meta_info('has_many') || {}}; } sub do_edit :Exported { @@ -41,9 +36,13 @@ sub do_edit :Exported { my ($obj) = @{$r->objects || []}; if ($obj) { # We have something to edit - $obj->update_from_cgi($h); + $obj->update_from_cgi($h => { + required => $r->{config}{$r->{table}}{required_cols} || [], + }); } else { - $obj = $self->create_from_cgi($h); + $obj = $self->create_from_cgi($h => { + required => $r->{config}{$r->{table}}{required_cols} || [], + }); $creating++; } if (my %errors = $obj->cgi_update_errors) { @@ -132,13 +131,18 @@ sub list :Exported { } sub setup_database { - my ($self, $config, $namespace, $dsn, $u, $p) = @_; + my ($self, $config, $namespace, $dsn, $u, $p, $opts) = @_; + $dsn ||= $config->{dsn}; + $u ||= $config->{user}; + $p ||= $config->{pass}; + $opts ||= $config->{opts}; $config->{dsn} = $dsn; $config->{loader} = Class::DBI::Loader->new( namespace => $namespace, dsn => $dsn, user => $u, password => $p, + options => $opts, ); $config->{classes} = [ $config->{loader}->classes ]; $config->{tables} = [ $config->{loader}->tables ];