[Catalyst] Catalyst and Moose with "has" many_to_many

Tomas Doran bobtfish at bobtfish.net
Thu Nov 25 19:54:09 GMT 2010


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

>
> 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!

>     is      => 'rw',
>     lazy    => 1,
> #  default => sub { MyApp::Controller::DB::Result::ActorRole->new },  
> # not!
> #  default => sub { ...->add_to_roles(??) }

Erm, no, you can't just magic a result class out of nothing with no  
parameters - you usually get them back from a ->search method on a  
resultset..

> )
>
> 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 ); # ??
>

I think you're confused here, if you have a Result instance, then the  
accessors on it will be the columns, e.g. $my_row->a_column or $my_row- 
 >many_to_many_accessor

Does that help?

Cheers
t0m




More information about the Catalyst mailing list