|-------------------| |-------------------| | TBL NAME = Article | | TBL NAME = Author | |-------------------| |-------------------| | articleId INT PrimKey | | authorId INT PrimKey| | authorId INT | | articleId INT | | title varchar(255) | | author varchar(32) | |other fields | | other fields | --------------------- --------------------- #### $article->author #### package MPDatabase::Article; use strict; use base 'MPDatabase::DBI'; __PACKAGE__->table('article'); __PACKAGE__->columns(Primary => qw/articleId/); __PACKAGE__->columns(All => qw/articleId topicId authorId title intro body postDateTime/); __PACKAGE__->has_a(topicId => 'MPDatabase::Topic'); __PACKAGE__->has_a(authorId => 'MPDatabase::Author'); __PACKAGE__->might_have( topic_class => 'MPDatabase::Topic' => qw/topic relativeImagePath imagePath alt/); __PACKAGE__->might_have( author_class => 'MPDatabase::Author' => qw/author email/); 1; #### package MPDatabase::Author; use strict; use base 'MPDatabase::DBI'; __PACKAGE__->table('author'); __PACKAGE__->columns(Primary => qw/authorId/); __PACKAGE__->columns(All => qw/authorId author email/); __PACKAGE__->has_many(articles => 'MPDatabase::Article'); 1; #### !/usr/bin/perl -w # use strict; use MPDatabase::Article; use MPDatabase::Author; my $article = MPDatabase::Article->retrieve(articleId => 5); print $article->author, "\n"; # This program does not produce any output #### <--- parse_params mysql_st_internal_execute Binding parameters: SELECT authorid FROM author WHERE authorid = '5' #### SELECT authorId FROM author A, article B WHERE A.authorID = B.authorId and B.articleId = 5