[Dbix-class] help needed in forming a 'and' and 'or' select
query using DBIx::Class
Peter Rabbitson
rabbit+dbic at rabbit.us
Mon Jan 21 13:40:37 GMT 2013
On Fri, Jan 18, 2013 at 10:19:25AM -0800, Rajeev Prasad wrote:
> Hello,
>
> I am trying to build a query based on two column values as folows:
>
> columnA = x (one char, any char - not null)
> columnB = zz _or_ x,xx,yyy,mm (comma seperated values or just one value)
>
>
> I am looking for rows where: (columnB contains either zz or mm...)
>
> columnA = x AND ( columnB = zz OR columnB LIKE '%mm%' )
>
>
>
> I am trying following which is not giving correct results.
>
>
> $val = 'mm';
>
> $my_rs = $schema->resultset('Mytable')->search({
> columnA => 'x',
> columnB => { like => 'zz' },
> columnB => { like => '%'.$val.'%' }
> });
>
Nobody explained why your original attempt did not work. What you feed
to search() is a plain hash, with keys columnA and columnB. Supplying
two values for the same hash-key has a well defined behavior - it only
takes the last one. Hence the extra "clarifications" as shown in earlier
replies.
Cheers!
More information about the DBIx-Class
mailing list