【发布时间】:2014-06-10 03:13:07
【问题描述】:
在我的项目中,我有 3 个表格:艺术家、专辑和曲目
结果艺术家:
...
__PACKAGE__->has_many(
'albums' => 'MYLIB::DB::Schema::Result::MyDir::Album',
{ 'foreign.artist_id' => 'self.id', },
);
...
结果专辑:
...
__PACKAGE__->belongs_to(
'artist' => 'MYLIB::DB::Schema::Result::Artist',
{ 'foreign.id' => 'self.artist_id', },
);
__PACKAGE__->has_many(
'tracks' => 'MYLIB::DB::Schema::Result::MyDir::Track',
{ 'foreign.album_id' => 'self.id', },
);
...
结果跟踪:
__PACKAGE__->belongs_to(
'album' => 'MYLIB::DB::Schema::Result::MyDir::Album',
{ 'foreign.id' => 'self.album_id', },
);
现在我有一个对象 $artist,我想通过 ID 获取一个 Track。
查询示例:
SELECT * FROM Tracks WHERE track_id = $x
【问题讨论】:
标签: perl dbix-class