]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI.pm
fix tabs/spaces
[maypole.git] / lib / Maypole / Model / CDBI.pm
index 14f2f0b8ca3e6e60751c722ddef578f80996b79f..4a83bcb08f5c402c91bb22bd04497a5208dde688 100644 (file)
@@ -39,6 +39,8 @@ See L<Maypole::Model::Base> for these:
 
 =item setup_database
 
+=item fetch_objects
+
 =back 
 
 =head1 Additional Commands
@@ -158,7 +160,7 @@ sub search : Exported {
     my $oper   = "like";                                # For now
     my %params = %{ $r->{params} };
     my %values = map { $_ => { $oper, $params{$_} } }
-      grep { defined $params{$_} and $fields{$_} } keys %params;
+      grep { length ($params{$_}) and $fields{$_} } keys %params;
 
     $r->template("list");
     if ( !%values ) { return $self->list($r) }
@@ -206,7 +208,7 @@ sub list : Exported {
 }
 
 sub setup_database {
-    my ( $self, $config, $namespace, $dsn, $u, $p, $opts ) = @_;
+    my ( $class, $config, $namespace, $dsn, $u, $p, $opts ) = @_;
     $dsn  ||= $config->dsn;
     $u    ||= $config->user;
     $p    ||= $config->pass;
@@ -233,4 +235,15 @@ sub class_of {
     return $r->config->loader->_table2class($table);
 }
 
+sub fetch_objects {
+    my ($class,$r)=@_;
+    my @pcs = $class->primary_columns;
+    if ( $#pcs ) {
+    my %pks;
+        @pks{@pcs}=(@{$r->{args}});
+        return $class->retrieve( %pks );
+    }
+    return $class->retrieve( %$r->{args}->[0] );
+}
+
 1;