FAQ
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',
is => 'rw',
lazy => 1,
default => sub { MyApp::Controller::Incident::IncidentForm->new },
)

then

$c->stash->{form} = $self->form; # etc

Piece of cake!



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

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've looked through
http://search.cpan.org/~frew/DBIx-Class-0.08124/lib/DBIx/Class/Relationship.pm#many_to_many
until my eyes cross on their own :(



Or am I barking up the wrong tree?

--
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/20101124/3b0424e8/attachment.htm

Search Discussions

  • Tomas Doran at Nov 25, 2010 at 7:52 pm

    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
  • Will Trillich at Nov 25, 2010 at 9:57 pm

    On Thu, Nov 25, 2010 at 1:54 PM, Tomas Doran 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: Catalyst@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/4a506e96/attachment.htm
  • Tomas Doran at Nov 26, 2010 at 7:02 pm

    On 25 Nov 2010, at 21:57, will trillich wrote:
    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.
    I don't care where the code physically lives - just how it's
    namespaced..

    Please please fix the namespace, as calling it MyApp::Controller::XXX
    _WILL GET IT LOADED AS A CONTROLLER BY CATALYST_

    Cheers
    t0m
  • Will Trillich at Nov 26, 2010 at 9:19 pm
    Roger that, will comply. Thanks!


    On Fri, Nov 26, 2010 at 1:03 PM, Tomas Doran wrote:

    On 25 Nov 2010, at 21:57, will trillich wrote:

    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.
    I don't care where the code physically lives - just how it's namespaced..

    Please please fix the namespace, as calling it MyApp::Controller::XXX _WILL
    GET IT LOADED AS A CONTROLLER BY CATALYST_


    Cheers
    t0m


    _______________________________________________
    List: Catalyst@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/20101126/6fa7a87c/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 25, '10 at 3:43a
activeNov 26, '10 at 9:19p
posts5
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Will Trillich: 3 posts Tomas Doran: 2 posts

People

Translate

site design / logo © 2022 Grokbase