[Dbix-class] Chaining multiple many-to-many relations

Jean-François Stenuit jfs at chryseis.be
Wed Dec 15 16:37:34 GMT 2010


Hi Felix,

This goes in the right direction :

my $rsApp = $rowUser->groups->search_related('bgroup_2_applications')->search_related('bapplication');

works and generate this query behind the scenes :
SELECT bapplication.id, bapplication.site_id, bapplication.code,
bapplication.comment FROM buser_2_group me JOIN bgroup bgroup ON
bgroup.id = me.group_id JOIN bgroup_2_application
bgroup_2_applications ON bgroup_2_applications.group_id = bgroup.id
JOIN bapplication bapplication ON bapplication.id =
bgroup_2_applications.application_id WHERE ( me.user_id = '8' )

groups->search_related('applications') does not work. Apparently,
search_related does not work with many-yo-many relationships.

Thanks for the hint,

-- Jean-François "Jef" Stenuit

On Wed, Dec 15, 2010 at 4:56 PM, Felix Antonius Wilhelm Ostmann
<ostmann at websuche.de> wrote:
> Test
> $user->groups->search_related('applications', {...});
> or
> $user->related_resultset('groups')->related_resultset('applications')->...
>
> Am 15.12.2010 16:18, schrieb Jean-François Stenuit:
>> Hi DBIC experts,
>>
>> Maybe a dumb question, maybe I'm doing it wrong, but I don't seem to
>> be able to chain two many-to-many relations.
>>
>> I'm re-writing (OO style) a RBAC system, where a user is part of a
>> group, and each group has access to a set of applications :
>>
>> user ----many-to-many---- group ----many-to-many----- application
>>
>> I'd like to use a shortcut of the form :
>> my $rsApplications=$rowUser->groups->applications
>>
>> But it does not seem to work. I get this error :  Can't locate object
>> method "applications" via package "DBIx::Class::ResultSet"
>>
>> Addressing the two many-to-many relationships independently works correctly.
>>
>> Is it at all possible to chain many-to-many relationships ?
>> DBIx::Class::Relationship doc has some hint about that "you cannot
>> call related_resultset and similar methods", so I suspect the answer
>> is negative. But I could be wrong.
>>
>> Another option would be to create a many-to-many relationship that
>> spawns all five tables ?
>>
>> Any hint welcome. Thanks in advance,
>>
>>
>> Jean-François "Jef" Stenuit
>>
>> _______________________________________________
>> 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
>>
>
>
> --
> Mit freundlichen Grüßen
>
> Felix Antonius Wilhelm Ostmann
> -----------------------------------------------------------
> Websuche Search Technology GmbH & Co. KG
> Martinistraße 3, D-49080 Osnabrück, Germany
> -----------------------------------------------------------
> Tel.: +49 541 40666-0, Fax: +49 541 40666-22
> Email: info at websuche.de, Web: www.websuche.de
> -----------------------------------------------------------
> AG Osnabrück - HRA 200252, Ust-IdNr.: DE814737310
> -----------------------------------------------------------
> Komplementärin: Websuche Search Technology Verwaltungs GmbH
> AG Osnabrück - HRB 200359, Geschäftsführer: Ansas Meyer
> -----------------------------------------------------------
>
> _______________________________________________
> 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