[Dbix-class] has_many relationship docs

Matt S Trout dbix-class at trout.me.uk
Thu Apr 27 21:10:16 CEST 2006


Toby Corkindale wrote:
> Did anyone come back (perhaps offlist) with an answer to this?
> 
> Reason I ask is that I'm just trying to get my head around adding objects via
> many_to_many relationships. Is there a shortcut method, a-la has_many's
> *_add_to() method?
> 
> ie.
> Actor has a many_to_many relationship to Roles, eg:
> Schema::Actor->many_to_many( roles => 'actor_roles', 'Schema::Roles');
> Is it possible to do something like:
> $actor->add_to_roles( { role => 'Sherlock Holmes' } );
> ?

$actor->roles->create(...);

if you really want the same behaviour as has_many, you could write

sub add_to_roles { shift->roles->create(@_); }

which is basically what the has_many rel generates :)

-- 
      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