The Class::DBI docs aren't especially clear on this but
might_have relationships have to have identical primary keys in both tables. This makes a
has_a relationship your only option since the
Author table naturally doesn't have a primary key of
articleId.
If you'd like to have the functionality you're describing, you could do something like the following (quite untested):
package MPDatabase::Article;
# ... set up table ...
__PACKAGE__->has_a(authorId => 'MPDatabase::Author');
{
no strict 'refs';
foreach my $m(MPDatabase::Author->columns()){
# keep from overriding existing methods...
next if __PACKAGE__->can($m);
# deploy shortcut sub
*{$m} = sub {
my $obj = shift;
return $obj->authorId->$m(@_);
};
}
}
Incidentally, I've found
might_have relationships to be of rather limited use.
-- Brian
UPDATE: tweaked method detection