[Dbix-class] Constructing a resultset()->search() with variable
number of ORs?
Chris Cole
chris at compbio.dundee.ac.uk
Mon Oct 26 16:36:21 GMT 2009
Hi,
I'd like to convert the below code to using a variable number of ORs on
the 'name' column. i.e. there may be a data3 as well as data1 and data2.
my $schema = DB::Schema->connect();
my @rows = $schema->resultset('Reads2expt')->search(
# select name rows on data1 OR data2 with abundance cutoffs
[
{
name => 'data1',
abundance => { '>' => 1 }
},
{
name => 'data2',
abundance => { '>' => 1 }
}
],
{
join => [qw/ read_id expt_id /],
order_by => 'me.read_id',
group_by => 'me.read_id',
prefetch => 'read_id',
cache => 1
}
);
I've gotten this far:
my @ors;
foreach my $data (qw/data1 data2/) {
push @ors, { name => $data, abundance => { '>' => $abund } };
}
my @rows = $schema->resultset('Reads2expt')->search(
@ors,
{
join => [qw/ read_id expt_id /],
order_by => 'me.read_id',
group_by => 'me.read_id',
prefetch => 'read_id',
cache => 1
}
);
but it gives me very different results and the DBIC_TRACE output shows
that it's doing a series of subselects, not expanding the OR construct.
Can anyone see where I'm going wrong?
Cheers,
Chris
More information about the DBIx-Class
mailing list