[Catalyst] getting the role id

Jason Kohles email at jasonkohles.com
Sun Feb 4 16:04:19 GMT 2007


On Feb 4, 2007, at 6:52 AM, Octavian Rasnita wrote:

> Hi,
>
> Is it possible to get the id of the roles of the current user from  
> $c->user?
>
> I found that I can get the role names using $c->user->roles, but I  
> need the id of those roles.
> Do I need to make another query to the database for finding this?
>

If you are using the normal many-to-many method for mapping roles,  
something like this:

User->has_many( 'map_user_role', 'User::Role', 'user_id' );
User->many_to_many( 'roles', 'map_user_role', 'role' );

Then you can get the roles objects with $c->user->roles, and the  
User::Role objects with $c->user->map_user_role.

-- 
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070204/3cb44845/attachment.htm


More information about the Catalyst mailing list