[Dbix-class] has_many relationship docs

Toby Corkindale tjc at wintrmute.net
Thu Apr 27 20:42:29 CEST 2006


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' } );
?

ta,
Toby

On Wed, Mar 01, 2006 at 09:24:37AM -0800, Tim McIntyre wrote:
> Hey all,
> 
> I'm trying out DBIC for the first time and something in the docs has  
> me scratching my head.  I'm pretty sure I'm just completely  
> misunderstanding something but this seems odd to me.
> 
> From the docs:
> 
> # in a Foo class (where Foo has many Bars)
> __PACKAGE__->has_many(bar => Bar, 'foo');
> my $f_resultset = $obj->foo;
> my $f_resultset = $obj->foo({ name => { LIKE => '%macaroni%' },  
> { prefetch => [qw/bar/]});
> my @f_obj = $obj->foo;
> $obj->add_to_foo(\%col_data);
> 
> 
> This is where my head is:
> 
> # in a Foo class (where Foo has many Bars)
> __PACKAGE__->has_many(bars => "My::Bar", 'foo_id');
> 
> # back in the main package or wherever
> my $bars = $foo_object->bars;
> $foo_object->add_to_bars(\%col_data);
> 
> 
> 1) Other than the prefetch example I don't see where the foo method  
> calls from the doc example come into play here?
> 
> 2) Why can't you pass instances to the add_to_* methods?
> 
> 
> Sorry about this but UGH!... IMHO foo, bar examples suck!  They are  
> just too generic.  More realistic examples are much more helpful to  
> us newbies.
> 
> Looks like a great project though, I'm excited.
> 
> Thanks in advance!
> Tim McIntyre

> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/

-- 
Turning and turning in the widening gyre/The falcon cannot hear the falconer;
Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world
(gpg --keyserver www.co.uk.pgp.net --recv-key B1CCF88E)



More information about the Dbix-class mailing list