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/[email protected]

Reply via email to