[Dbix-class] Help with Many to Many Relationships

Dave Cross dave at dave.org.uk
Wed Jun 17 15:11:54 GMT 2009


On 17/06/2009 13:12, Ian Wells wrote:
> 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);

Thanks. That's exactly what I was looking for. I'd have got there myself 
too - given another eight or ten hours of trying :-/

Cheers,

Dave...



More information about the DBIx-Class mailing list