我正在使用 cakephp 2.1 并编写如下的 sql 语句。
SELECT * FROM industry
LEFT JOIN movie ON movie.industry_id = industry.id
LEFT JOIN (
SELECT MAX(id) AS TID ,movie_id FROM trailer
GROUP BY movie_id
) AS c ON c.movie_id = movie.id
LIMIT 0, 4;
其中行业是“行业”模型,电影是“电影”模型,预告片是“预告片”模型,我试过这个。
$options['joins'] = array(
array(
'table' => 'movies',
'alias' => 'Movie',
'type' => 'left',
'conditions' => array('Industry.id = Movie.industry_id')),
array(
'table' => 'movie_trailers',
'alias' => 'Trailer',
'type' => 'left',
'conditions' => array('Trailer.movie_id = Movie.id')));
$trailers = $this->Industry->find('all', $options);
所以请建议我将此语句转换为 cakephp 语句。