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

Peter Rabbitson rabbit+dbic at rabbit.us
Thu May 2 06:25:16 GMT 2013


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

Cheers




More information about the DBIx-Class mailing list