For this to work, you'd need to specify which columns you're returning. So,
something like:

$schema->resultset('First')->search({
    'second.attr' => { -in => [ 1, 2, 3 ] },
}, {
    join => 'second',
    select => [ 'me.id', 'me.attr1', 'me.attr2' ],
    distinct => 1,
});

Note: this means you won't be able to do $row->attr3 like you'd normally be
able to. Because, well, you didn't get it back. :)


On Mon, Jul 1, 2013 at 8:50 AM, Bill Moseley <mose...@hank.org> wrote:

>
>
> On Mon, Jul 1, 2013 at 6:57 AM, Dmitry Belyavsky <beld...@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 => {-in => [1,2,3]}},
>> {join => 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=second.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/ResultSet.pm#distinct
>
>
>
> --
> Bill Moseley
> mose...@hank.org
> _______________________________________________
> 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
>



-- 
Thanks,
Rob Kinyon
_______________________________________________
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

Reply via email to