[CDBI] Re: Many-to-many relationships of same type?

Ciaran Hamilton class-dbi at theblob.org
Wed Jun 20 09:55:05 BST 2007


On 6/19/07, Edward J. Sabol <sabol at alderaan.gsfc.nasa.gov> 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.



More information about the ClassDBI mailing list