[Catalyst] Catalyst and Moose with "has" many_to_many
will trillich
will.trillich at serensoft.com
Thu Nov 25 21:57:51 GMT 2010
On Thu, Nov 25, 2010 at 1:54 PM, Tomas Doran <bobtfish at bobtfish.net> wrote:
>
> On 25 Nov 2010, at 03:43, will trillich wrote:
>
> Greetings Catalystery: Got a new question, trying to implement a
>> many_to_many
>> relationship via Moose... The DBIC portion of the puzzle is
>> straightforward, we've got
>> that working just fine.
>>
>> Here's part I understand -- we have a controller that's referring to a
>> form:
>>
>> has 'form' =3D> (
>> isa =3D> 'MyApp::Controller::Incident::IncidentForm',
>>
>
> Ewww!
>
> 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
Right. :) These are 'inlined' within the controller that's the only place
where they're used. E.g.
package Spill::Controller::Spill;
use Moose;
#...
{
package Spill::Controller::Incident::IncidentForm;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
#...
}
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.
>> But how would you represent and then refer to a many_to_many relationship
>> such as
>>
>> has 'actor_role' =3D> (
>> isa =3D> 'MyApp::Controller::DB::Result::ActorRole',
>>
>
> 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!
Turns out this is blitheringly simple thanks for FormHandler and DBIC --
simply:
package Spill::Schema::DB::Result::Incident;
#...
__PACKAGE__->has_many( map_incident_agency =3D>
'Spill::Schema::DB::Result::IncidentAgency' =3D> 'incident' );
__PACKAGE__->many_to_many( agencies =3D> 'map_incident_agency',
'agency' );
package Spill::Form::IncidentForm;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
#...
has_field 'agencies' =3D> ( type =3D> 'Multiple' );
has_field 'contractors' =3D> ( type =3D> 'Multiple' );
)
>>
>> And then once we get the "has" straightened out, how do we use it?
>>
>> %roles =3D $self->actor_role( @get_roles ); # ??
>> @success =3D $self->actor_role( %set_new_roles ); # ??
>>
>>
>
>
> Does that help?
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-- =
Failure is not important. How you overcome it, is.
-- Nick Vujicic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101125/4a506=
e96/attachment.htm
More information about the Catalyst
mailing list