[Maypole] Maypole::Model::CDBI search patch

Joshua Keroes jkeroes@eli.net
Fri, 29 Oct 2004 18:15:12 -0700


Searches do not work as expected. If I don't enter '%' into every 
field, the allegedly null fields turn into empty strings and make their 
way into the search query.

Solution? Don't add param values to the search query if they're either 
undefined or the empty string. (0 is okay, that's why I didn't test 
against just $params{$_})

*** CDBI.orig   Fri Oct 29 18:07:07 2004
--- CDBI.pm     Fri Oct 29 18:07:47 2004
***************
*** 158,164 ****
       my $oper   = "like";                                # For now
       my %params = %{ $r->{params} };
       my %values = map { $_ => { $oper, $params{$_} } }
!       grep { defined $params{$_} and $fields{$_} } keys %params;

       $r->template("list");
       if ( !%values ) { return $self->list($r) }
--- 158,165 ----
       my $oper   = "like";                                # For now
       my %params = %{ $r->{params} };
       my %values = map { $_ => { $oper, $params{$_} } }
!       grep { defined $params{$_} && $params{$_} ne '' && $fields{$_} }
!       keys %params;

       $r->template("list");
       if ( !%values ) { return $self->list($r) }

__END__

Cheers,
Joshua