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 = 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 object. <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. -Tim On Wed, Jul 11, 2012 at 1:25 PM, Robyn Jonahs <[email protected]>wrote: > 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. > > Thanks > RJ > > On Wed, Jul 11, 2012 at 12:48 PM, Tim Anderson <[email protected]> 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 trying >> to write the same type of request across a multiple key relationship. >> >> >> -Tim >> >> >> On Wed, Jul 11, 2012 at 11:29 AM, Robyn Jonahs >> <[email protected]>wrote: >> >>> Thanks, that worked. Now I am off to see why. >>> >>> [ snip ] >>> >> >> _______________________________________________ >> List: [email protected] >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst >> Searchable archive: >> http://www.mail-archive.com/[email protected]/ >> Dev site: http://dev.catalyst.perl.org/ >> >> > > _______________________________________________ > List: [email protected] > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/[email protected]/ > Dev site: http://dev.catalyst.perl.org/ > >
_______________________________________________ List: [email protected] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
