[html-formfu] HTML::FormFu::Model::DBIC and Many-to-many

Ascii King tech at swattermatter.com
Mon Sep 28 03:09:24 GMT 2009


Ascii King wrote:
>
> list_hero.tt2
> ---------------------
> <table>
> <thead>
>    <th>Name</th>
>  <th>Skills</th>
> </thead>
>
> [% FOREACH hero IN object -%]
>  </tr>
>    <td>[% hero.hero_name %]</a></td>
>    <td>
>      [% FOREACH unique_skill = hero.skills %]
>          [% unique_skill.skill_name %] [[% 
> unique_skill.hero_skill.rank %]]<br />
>      [% END %]
>    </td>
>  </tr>
> [% END -%]
> </table>
>
> Please notice the odd relationship to get the rank to display. [% 
> unique_skill.hero_skill.rank %]
> If there is some data-integrity reason why I can't do it this way, 
> please tell me. I hope this helps someone.
Ok. This relationship is odd because it is wrong. The actual FOREACH 
loop should look like this.


      [% FOREACH unique_skill = hero.hero_skill %]
          [[% unique_skill.rank %]] [% unique_skill.skill_id.skill_name 
%]<br />
      [% END %]

In this case ([% unique_skill.skill_id.skill_name %]) skill_id is 
referring to the belongs_to relationship in the intermediary table 
HeroSkill.  It is taking the unique_skill object created in the FOREACH 
loop and applying the relationship that links it to the Skill table.




More information about the HTML-FormFu mailing list