[Dbix-class] Multiple joins, noob questions

Александер Пономарёв shootnix at gmail.com
Sun May 15 13:40:13 GMT 2011


Thanks to all, I was all clear!

2011/5/14 Denny <2011 at denny.me>:
> On Sat, 2011-05-14 at 13:40 +0600, Александер Пономарёв wrote:
>> My question is: how can I organize my schema-library to get user and
>> his role with one step? To get $user->user_name & $user->role_name?
>
> Assuming (from your table structure) that a user can have multiple
> roles, then you can't just get $user->role_name - it won't know which
> one you want.  You could get $user->roles though, by having a
> many_to_many relationship, and then you can search or loop through those
> roles.  You might also want a $user->has_role() method for convenience.
>
> Take a look at the user / role / user_role bits of ShinyCMS for an
> example that I think is pretty close to what you're trying to do:
>
> https://github.com/denny/ShinyCMS/blob/master/lib/ShinyCMS/Schema/Result/User.pm
>
> https://github.com/denny/ShinyCMS/blob/master/lib/ShinyCMS/Schema/Result/Role.pm
>
> https://github.com/denny/ShinyCMS/blob/master/lib/ShinyCMS/Schema/Result/UserRole.pm
>
> Hope that helps!
>
> Regards,
> Denny
>
>
> _______________________________________________
> 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