[Dbix-class] many_to_many

Matt S Trout dbix-class at trout.me.uk
Tue Sep 5 14:32:33 CEST 2006


Lee Goddard wrote:
> Hi there
>  
> I'm new to DBIx::Class, and am having problems understanding the syntax
> of many_to_may relationshiops.
> 
> I have spent some times finding and reading the various docs but get
> stuck with (from Cookbook):
> 
> __PACKAGE__->has_many('user_address' => 'My::UserAddress', 'user');
> __PACKAGE__->many_to_many('addresses' => 'user_address', 'address');
> 
> Is the following reading correct?
> 
> __PACKAGE__->has_many(
>     $table_name, $tables_object, $primary_key
> );
>  __PACKAGE__->many_to_many(
>     $table_name, $table_name_from_has_many, $primary_key
> );

Nope, completely wrong :)

__PACKAGE__->has_many(
   $relationship_name, $foreign_class, $id_in_this_class_if_not_pk
);

__PACKAGE__->many_to_many(
   $many_many_name, $has_many_name, 
$belongs_to_from_the_has_many_to_the_other_side_name
);

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list