[Catalyst] The Definitive Guide to Catalyst ... p. 165 listing
all users and their roles
tja824 at gmail.com
Wed Jul 11 18:57:59 GMT 2012
Sorry Robyn (and others I may have misled), I'm wrong.
I reviewed again, and you're not leveraging the many_to_many at all.
You're following a path that looks like this:
[% FOREACH role =3D user.user_roles %]
User.pm has a 'has_many' relationship called 'user_roles' that you are
leveraging, in each iteration of this loop role is set to a a UserRole row
<li>[% role.role.role %]</li>
UserRole row object has 'belongs_to' relationship called 'role' (the second
'role' in the TT string above. This is why fREW's answer works.
Originally, using role_id accessed the value of role_id column in the
UserRole row, but you need to go one level deeper, so you use the
belongs_to 'role' to step to the related Role object row.
The related Role object has a value of role (the third 'role' in the TT
string), and this is the value that you want printed out.
[% END %]
I hope this helps. I'm learning too. I've taken a lot from this list, and
I'm trying to give back.
On Wed, Jul 11, 2012 at 1:25 PM, Robyn Jonahs <learn.catalyst at gmail.com>wro=
> Thanks Tim,
> I thought that the many_to_many was a relationship bridge and as limited
> to what it could do. I was studying the many_to_Many examples in the book
> to help my real problem in a test application I am trying to work on. I
> guess I should start a new thread for questions related to that. I will do
> that and try to continue understanding the relationships.
> On Wed, Jul 11, 2012 at 12:48 PM, Tim Anderson <tja824 at gmail.com> wrote:
>> <li>[% role.role.role %]</li> works because you're accessing the role
>> name (the third 'role') through the 'role' accessor (the second 'role')
>> which is defined in your many-to-many relationship:
>> __PACKAGE__->many_to_many("roles", "user_roles", *"role"*);
>> This is one of the beauties of DBIC; as soon as you have your
>> relationships defined, you have paths to the data you need. Imagine try=
>> to write the same type of request across a multiple key relationship.
>> On Wed, Jul 11, 2012 at 11:29 AM, Robyn Jonahs <learn.catalyst at gmail.com=
>>> Thanks, that worked. Now I am off to see why.
>>> [ snip ]
>> List: Catalyst at lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> Dev site: http://dev.catalyst.perl.org/
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> Dev site: http://dev.catalyst.perl.org/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Catalyst