[Dbix-class] Multiple ands in where clause
David Ihnen
davidihnen at gmail.com
Fri May 28 21:59:09 GMT 2010
Perchane did you try something like this:
$rs = $schema->resultset('IncOpcode')->search(
{ desc => { -like => [ map { '%'.$_.'%' } @TERMS ] }
} );
David
On Fri, May 28, 2010 at 12:57 PM, Dennis Daupert <ddaupert at gmail.com> wrote:
> I need to '-and' a varying number of variables in a
> where clause in my application. I've tried building
> sets of search terms in an array, so that I can
> iterate through the array to try various queries,
> but haven't so far been able to find the correct
> format. The idea is to find one result in a list
> by trying variables A and B, but if that search
> gets more than one result, then try variables
> A and B and C, and so on.
> I've tried code iterations like the following :
> my @search_strings = (
> '{ \'like\', "%$Term1%" }',
> '{ \'like\', "%$Term1%" },{ \'like\', "%$Term2%" }',
> ...etc...
> );
> So that I can do something like this:
> foreach my $search_string ( @search_strings ) {
> $rs = $schema->resultset('IncOpcode')->search({
> desc => [ -and => $search_string
> ],
> });
> $rs_count = $rs->count;
> next SEARCHSTRING if $rs_count > 1;
> if ( $rs_count == 1 ) {
> # do stuff
> }
> }
> The format in $search_string is wrong. I get 0 hits.
> What is the correct format to do this?
> /dennis
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
--
"If only I could get rid of hunger by rubbing my belly" - Diogenes
More information about the DBIx-Class
mailing list