[Dbix-class] Search condition on integer data-type column

Rob Kinyon rob.kinyon at gmail.com
Tue Mar 23 14:16:51 GMT 2010


2010/3/23 Hetényi Csaba <csabiwork at tata.hu>:
>   my $rs = $c->model('DB::Users')->search(
>       {
>           nem => $nem,
>           megye => $megye,
>       },
>   );
>
>
> BUT, if the user wants to see all of the rows (but the 'nem' clause still
> applied) what have to put in
> $megye?
> (i tried "LIKE", "%" things but it is for text type)
> Is there a way to ignore "megye => $megye" line completely in this case, but
> remain other clauses in
> search ?
>
> In old times (before Catalyst) i have builded a custom sql statement for
> every user request with string-based operations:
>
> $sql="SELECT * FROM users WHERE nem = $nem";
> $sql = "$sql AND megye = $megye" if $megye != 0;

my $search_clause = { nem => $nem };
if ( $megye ) { $search_clause->{megye} = $megye; }

my $rs = $c->model('Users')->search( $search_clause );

It's just a hashref.

Rob



More information about the DBIx-Class mailing list