在我的项目中,我有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