[CDBI] Re: Many-to-many relationships of same type?
"Ciaran Hamilton" <[email protected]> Wed, 20 Jun 2007 09:55:05 +0100
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
On 6/19/07, Edward J. Sabol <sabol-2oVx0MVsMgiP/[email protected]> wrote: > You need to use the three-argument version of has_many(). The third argument > allows you to explicitly specify the name of the foreign key. I remember > being confounded by this when I first started using Class::DBI many moons ago > and tried to set up my first many-to-many relationship. It's a shame the > Class::DBI documentation doesn't cover this aspect very well. The examples in > the documentation all assume the foreign key and the class have the same > name. Ahhhh, thanks. Yeah, that isn't very well documented - a complaint I seem to see quite often about Class::DBI. :) You were almost right in your example - what I actually needed was: __PACKAGE__->has_many(friends => [ 'LJData::Friends' => 'friend' ] => 'friendof'); That is, using 'friendof' instead of 'userid'. It now works fine. :D Question, though - would you recommend DBIx::Class as well, as suggested by Matt? If I'm going to make new code I may as well get it right off the bat. What's your opinion? - Ciaran.