我正在尝试将 Class::DBI 与一个简单的单亲 -> 可能与孩子的关系一起使用:
Data::Company->table('Companies');
Data::Company->columns(All => qw/CompanyId Name Url/);
Data::Company->has_many(offers => 'Data::Offer'=>'CompanyId'); # =>'CompanyId'
和
Data::Offer->table('Offers');
Data::Offer->columns(All => qw/OfferId CompanyId MonthlyPrice/);
Data::Offer->has_a(company => 'Data::Company'=>'CompanyId');
我尝试添加新记录:
my $company = Data::Company->insert({ Name => 'Test', Url => 'http://url' });
my $offer = $company->add_to_offers({ MonthlyPrice => 100 });
但我得到:
Can't locate object method "add_to_offers" via package "Data::Company"
我查看了古典 Music::CD 示例,但我无法弄清楚我做错了什么。