On Thu, Nov 25, 2010 at 1:54 PM, Tomas Doran <[email protected]> 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' => (
>>    isa     => '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' => (
>>    isa     => '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     =>
'Spill::Schema::DB::Result::IncidentAgency'     => 'incident' );
__PACKAGE__->many_to_many( agencies     => 'map_incident_agency',
'agency' );


package Spill::Form::IncidentForm;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
#...
has_field 'agencies' => ( type => 'Multiple' );
has_field 'contractors' => ( type => 'Multiple' );



)
>>
>> And then once we get the "has" straightened out, how do we use it?
>>
>> %roles = $self->actor_role( @get_roles ); # ??
>> @success = $self->actor_role( %set_new_roles ); # ??
>>
>>
>
>
> Does that help?
>
> Cheers
> t0m
>
>
> _______________________________________________
> 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/
>



-- 
Failure is not important. How you overcome it, is.
-- Nick Vujicic
_______________________________________________
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/

Reply via email to