<br><br><div class="gmail_quote">On Thu, Nov 25, 2010 at 1:54 PM, Tomas Doran <span dir="ltr">&lt;<a href="mailto:bobtfish@bobtfish.net">bobtfish@bobtfish.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On 25 Nov 2010, at 03:43, will trillich wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Greetings Catalystery: Got a new question, trying to implement a many_to_many<br>
relationship via Moose... The DBIC portion of the puzzle is straightforward, we&#39;ve got<br>
that working just fine.<br>
<br>
Here&#39;s part I understand -- we have a controller that&#39;s referring to a form:<br>
<br>
has &#39;form&#39; =&gt; (<br>
    isa     =&gt; &#39;MyApp::Controller::Incident::IncidentForm&#39;,<br>
</blockquote>
<br></div>
Ewww!<br>
<br>
Catalyst will try to load all components under MyApp::Controller as controllers. This module clearly isn&#39;t - please move it to another namespace, e.g. MyApp::Form::Incident</blockquote><div> </div><div>Right. :) These are &#39;inlined&#39; within the controller that&#39;s the only place where they&#39;re used. E.g.</div>
<div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">package Spill::Controller::Spill;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">use Moose;</font></div>
</div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">#...</font></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">{</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    package Spill::Controller::Incident::IncidentForm;</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    use HTML::FormHandler::Moose;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    extends &#39;HTML::FormHandler::Model::DBIC&#39;;</font></div>
</div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    #...</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">}</font></div><div><br></div><div>Took that idea from the code generated by InstantCRUD, seems kinda nice! If these forms were useful in more than one place then we&#39;d certainly pull them into their own files in their own tree-branches.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
But how would you represent and then refer to a many_to_many relationship such as<br>
<br>
has &#39;actor_role&#39; =&gt; (<br>
    isa     =&gt; &#39;MyApp::Controller::DB::Result::ActorRole&#39;,<br>
</blockquote>
<br></div>
You haven&#39;t called your DBIC schema yApp::Controller::DB have you? This is really really bad - as Catalyst will be trying to load every DB row and ResultSet class as a controller!</blockquote><div><br></div><div>Turns out this is blitheringly simple thanks for FormHandler and DBIC -- simply:</div>
<div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">package Spill::Schema::DB::Result::Incident;</font></div></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">#...</font></div>
<div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">__PACKAGE__-&gt;has_many( map_incident_agency     =&gt; &#39;Spill::Schema::DB::Result::IncidentAgency&#39;     =&gt; &#39;incident&#39; );</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">__PACKAGE__-&gt;many_to_many( agencies     =&gt; &#39;map_incident_agency&#39;,     &#39;agency&#39; );</font></div></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><div><br></div><div>package Spill::Form::IncidentForm;</div><div>use HTML::FormHandler::Moose;</div><div>extends &#39;HTML::FormHandler::Model::DBIC&#39;;</div>
<div>#...</div></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">has_field &#39;agencies&#39; =&gt; ( type =&gt; &#39;Multiple&#39; );</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"></font><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">has_field &#39;contractors&#39; =&gt; ( type =&gt; &#39;Multiple&#39; ); </font></div>
<div><br></div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

)<br>
<br>
And then once we get the &quot;has&quot; straightened out, how do we use it?<br>
<br>
%roles = $self-&gt;actor_role( @get_roles ); # ??<br>
@success = $self-&gt;actor_role( %set_new_roles ); # ??<br>
<br>
</blockquote>
<br></div><br>
<br>
Does that help?<br>
<br>
Cheers<br>
t0m<br>
<br>
<br>
_______________________________________________<br>
List: <a href="mailto:Catalyst@lists.scsys.co.uk" target="_blank">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" target="_blank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Failure is not important. How you overcome it, is.<br>-- Nick Vujicic<br>