[Dbix-class] ORing searches

Alan Humphrey alan.humphrey at comcast.net
Fri Jan 20 22:19:32 CET 2006


I'd like to search for the same value in multiple columns.  I tried this:

my @result = BirdWeb::Admin::Model::Staging->class('Birds')->search_like ({
		    bird_common_name => '%robin%',
      	    genus_scientific_name => '%robin%'
	
},
	
{
                join => [qw/default_bird_common_name_id
			       genus_id/]
	
});

which, as expected, produces an AND select.  Checking the SQL::Abstract docs
it looks like this should work:

my @result = BirdWeb::Admin::Model::Staging->class('Birds')->search_like ({
		    -nest => [bird_common_name => '%robin%',
				  genus_scientific_name => '%robin%']
	
},
	
{
           	    join => [qw/default_bird_common_name_id
				 genus_id/]
	
});

But the resulting SQL is whack:

SELECT me.washington_map_id, me.taxonomic_order, me.genus_id,
me.default_bird_common_name_id, me.breeding, me.habitat, me.image_id,
me.nesting, me.diet, me.species_name_id, me.id, me.north_america_map_id,
me.migration, me.conservation_status, me.default_sound_id,
me.generic_bird_common_name_id, me.identification, me.behavior, me.voice,
me.notes, me.where_found FROM birds me  JOIN bird_common_names
default_bird_common_name_id ON ( default_bird_common_name_id.id =
me.default_bird_common_name_id )  JOIN genera genus_id ON ( genus_id.id =
me.genus_id ) WHERE ( ( ( ( like = ? ) OR ( like = ? ) OR ( like = ? ) OR (
like = ? ) ) ) ): bird_common_name %robin% genus_scientific_name %robin%

Note the bind variables.

Is there another technique?

- Alan




More information about the Dbix-class mailing list