[Dbix-class] many_to_many and search_related

Rolf Schaufelberger rs at plusw.de
Thu Sep 21 18:16:41 CEST 2006


Hi, 

Am Donnerstag 21 September 2006 17:59 schrieb Matt S Trout:
> Rolf Schaufelberger wrote:
> > Hi,
> >
> >> Rolf Schaufelberger wrote:
> >>> Hi,
> >>> I'm currently trying to move my application from CDBI to Dbix::Class.
> >>>
> >>> Now I have a many_to many relationship and I want to do a search on the
> >>> related table as described in the pod. yet I get an errror:
> >>>
> >>> DBIx::Class::Relationship::Base::search_related(): No such relationship
> >>> motive at t/05_format.t line 26
> >>>
> >>> yet, doing fetching all objects works for both directions,
> >>>
> >>> the lines are :
> >>> PW::DB::Format.pm :
> >>>
> >>> ...
> >>> __PACKAGE__->has_many(mformate   => 'PW::DB::MFormat', 'format_id');
> >>> __PACKAGE__->many_to_many('motive' => 'mformate', 'motiv_id');
> >>>
> >>>
> >>> PW::DB::Motiv.pm :
> >>> ...
> >>> __PACKAGE__->has_many( mformate  => 'PW::DB::MFormat', 'motiv_id');
> >>> __PACKAGE__->many_to_many('formate' => 'mformate', 'format_id');
> >>
> >> many-many is a bridge across two relationships.
> >>
> >> $obj->motive
> >>
> >> is pretty much equivalent to
> >>
> >> $obj->search_related('mformate')->search_related('motiv_id')
> >
> > Ok , so
> >
> > my $ap2 = $f->search_related('mformate')->search_related('motiv_id',
> > {name=>'Airplane'});
> >
> > works.
> >
> > But according to the docs  in Relationship.pm
> > "..
> > MyDB::Schema::Role->many_to_many('actors' => 'actorroles', 'actor');
> > $schema->resultset('Role')->search_related('actors', { Name => 'Fred' });
> > .."
>
> Hmm, that may be a doc error
>
> $role->actors->search({ Name => 'Fred' });
>
> will work though - but the relname/mmname methods aren't carried up to the
> resultset class to try and avoid collisions.

Yes, that works. So the error seems to be with the docs. 

Thanks. 

Rolf Schaufelberger



More information about the Dbix-class mailing list