[Dbix-class] Help with Many to Many Relationships

Ian Wells ijw at cack.org.uk
Wed Jun 17 12:12:00 GMT 2009


2009/6/17 Jason Galea <lists at eightdegrees.com.au>:
> Hi Dave,
>
> package DB::Film;
>
> ...
>
> # has many actors
> __PACKAGE__->has_many('film_actor_maps' => 'DB::FilmActorMap', 'product');
> __PACKAGE__->many_to_many('actors' => 'film_actor_maps', 'actor');
>
> __PACKAGE__->belongs_to('director' => 'DB::Director');


I'd do it the other way around:

package DB::Actor;
...
# Has many films
__PACKAGE__->has_many('actor_film_maps' => 'DB::FilmActorMap', 'product');
__PACKAGE__->many_to_many('films' => 'actor_film_maps', 'film');

my $rs = $actor->films->search(director => 39);



More information about the DBIx-Class mailing list