[Dbix-class] Fetching distinct data

Bill Moseley moseley at hank.org
Mon Jul 1 15:50:49 GMT 2013


On Mon, Jul 1, 2013 at 6:57 AM, Dmitry Belyavsky <beldmit at gmail.com> wrote:

> Greating!
>
> I have 2 tables having one-to-many relation.
>
> I want to get all data from the 1st table filtered by an attr from the 2nd
> one.
>
> So I write
>
> $schema->resultset("First")->search({seconds.attr =3D> {-in =3D> [1,2,3]}=
},
> {join =3D> second} );
>
> The resulting queue does not contain the DISTINCT keyword so I get much
> more records in the resultset than I want.
>
> So how can I enforce the DBIx::Class to write a query like
>
> Select distinct me.id, me.attr1, me.attr2
> from first me
> left join second ON me.id=3Dsecond.first_id
> where second.attr not in (1,2,3)
>

Is this what you are after?

http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/ResultS=
et.pm#distinct



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130701/a4b=
d4ed7/attachment.htm


More information about the DBIx-Class mailing list