[Dbix-class] Re: help needed in forming a 'and' and 'or' select query using DBIx::Class

Rajeev Prasad rp.neuli at yahoo.com
Tue Jan 22 02:15:07 GMT 2013


=A0
Thanks to all for help and explanation as to why so.
=A0
I liked the below solution the best. thx again.
=A0
=A0
=A0


________________________________
From: Dagfinn Ilmari Manns=E5ker <ilmari at ilmari.org>
To: dbix-class at lists.scsys.co.uk =

Sent: Monday, January 21, 2013 4:34 AM
Subject: [Dbix-class] Re: help needed in forming a 'and' and 'or' select qu=
ery using DBIx::Class

Michele Beltrame <mb at cattlegrid.info> writes:

> Hello!
>
>> columnA =3D x AND ( columnB =3D zz OR columnB LIKE '%mm%' )
>
> It should be like this:
>
> $val =3D 'mm';
> $my_rs =3D $schema->resultset('Mytable')->search({
>=A0 =A0 =A0 =A0 =A0 =A0 =A0 columnA =3D> 'x',
>=A0 =A0 =A0 =A0 =A0 =A0 =A0 -or =3D> [
>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 columnB =3D> 'zz',
>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 columnB =3D> { like =3D> '%'.$=
val.'%' }
>=A0 =A0 =A0 =A0 =A0 =A0 =A0 ],
> });

Or a slightly more concise version:

my $rs =3D $schema->resultset('MyTable')->search({
=A0 =A0 columnA =3D> 'x',
=A0 =A0 columnB =3D> [ 'zz', { like =3D> '%'.$val'%' } ],
});


-- =

"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of."=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 -- Skud's Meta-Law


_______________________________________________
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/dbix-class@lists.scsys.co=
.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130121/12d=
21bb1/attachment.htm


More information about the DBIx-Class mailing list