[Dbix-class] Multiple ands in where clause
Dennis Daupert
ddaupert at gmail.com
Fri May 28 19:57:07 GMT 2010
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 =3D (
'{ \'like\', "%$Term1%" }',
'{ \'like\', "%$Term1%" },{ \'like\', "%$Term2%" }',
...etc...
);
So that I can do something like this:
foreach my $search_string ( @search_strings ) {
$rs =3D $schema->resultset('IncOpcode')->search({
desc =3D> [ -and =3D> $search_string
],
});
$rs_count =3D $rs->count;
next SEARCHSTRING if $rs_count > 1;
if ( $rs_count =3D=3D 1 ) {
# do stuff
}
}
The format in $search_string is wrong. I get 0 hits.
What is the correct format to do this?
/dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100528/88d=
4ac83/attachment.htm
More information about the DBIx-Class
mailing list