<br><br><div class="gmail_quote">On Thu, Nov 25, 2010 at 1:54 PM, Tomas Doran <span dir="ltr"><<a href="mailto:bobtfish@bobtfish.net">bobtfish@bobtfish.net</a>></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've got<br>
that working just fine.<br>
<br>
Here's part I understand -- we have a controller that's referring to a form:<br>
<br>
has 'form' => (<br>
isa => 'MyApp::Controller::Incident::IncidentForm',<br>
</blockquote>
<br></div>
Ewww!<br>
<br>
Catalyst will try to load all components under MyApp::Controller as controllers. This module clearly isn't - please move it to another namespace, e.g. MyApp::Form::Incident</blockquote><div> </div><div>Right. :) These are 'inlined' within the controller that's the only place where they're used. E.g.</div>
<div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">package Spill::Controller::Spill;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">use Moose;</font></div>
</div><div><font class="Apple-style-span" face="'courier new', monospace">#...</font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> package Spill::Controller::Incident::IncidentForm;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> use HTML::FormHandler::Moose;</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> extends 'HTML::FormHandler::Model::DBIC';</font></div>
</div><div><font class="Apple-style-span" face="'courier new', monospace"> #...</font></div><div><font class="Apple-style-span" face="'courier new', 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'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 'actor_role' => (<br>
isa => 'MyApp::Controller::DB::Result::ActorRole',<br>
</blockquote>
<br></div>
You haven'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="'courier new', monospace">package Spill::Schema::DB::Result::Incident;</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace">#...</font></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace">__PACKAGE__->has_many( map_incident_agency => 'Spill::Schema::DB::Result::IncidentAgency' => 'incident' );</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">__PACKAGE__->many_to_many( agencies => 'map_incident_agency', 'agency' );</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><div><br></div><div>package Spill::Form::IncidentForm;</div><div>use HTML::FormHandler::Moose;</div><div>extends 'HTML::FormHandler::Model::DBIC';</div>
<div>#...</div></font></div><div><font class="Apple-style-span" face="'courier new', monospace">has_field 'agencies' => ( type => 'Multiple' );</font></div><div><font class="Apple-style-span" face="'courier new', monospace"></font><font class="Apple-style-span" face="'courier new', monospace">has_field 'contractors' => ( type => 'Multiple' ); </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 "has" straightened out, how do we use it?<br>
<br>
%roles = $self->actor_role( @get_roles ); # ??<br>
@success = $self->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>