[Dbix-class] Duplication of records in many-to-many prefetch

Shea Levy shea.levy at logicblox.com
Thu May 2 15:01:37 GMT 2013


On 05/02/2013 02:25 AM, Peter Rabbitson wrote:
> On Wed, May 01, 2013 at 06:16:57PM -0400, Shea Levy wrote:
>> Hi all,
>>
>> In my project, a user can have multiple roles and multiple users can
>> have the same role. The username is the primary key for the users
>> table. When I run a query like:
>>
>> ->search({ 'me.username' => $username}, {
>>        columns => [ "me.fullname", "me.emailaddress", "me.username",
>> "userroles.role" ],
>>        join => "userroles"
>>      })
>>
>> for a user with multiple roles, though, I get multiple results for
>> that user, each with a different role (rather than one result with
>> multiple roles). Is this behavior expected?
> 100% expected. A join is just a join, there is no deduplication just
> like in SQL.
>
>> Is there any way to coalesce these separate records into one?
> https://metacpan.org/module/DBIx::Class::ResultSet#collapse

Ah, thanks, collapse is exactly what I wanted!

> https://metacpan.org/module/DBIx::Class::ResultSet#prefetch
>
> Cheers
>
>
> _______________________________________________
> 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




More information about the DBIx-Class mailing list