连接表排序的CakePHP分页不适用于连接表字段.但是对于自定义的sql join查询工作正常.请帮我出来
看下面的示例代码..我有Artist.name连接表字段顺序.
$this->paginate = array( 'fields' => array( 'id','Song.title','Song.date','Artist.id AS artist_id','Artist.name AS artist_name','COUNT(SongViews.id) AS views' ),'group' => array('ArtistsSong.song_id'),'recursive' => 0,'limit' => 20,'joins' => array( array( 'table' => 'tbl_artists_songs','alias' => 'ArtistsSong','conditions'=> array('Song.id = ArtistsSong.song_id') ),array( 'table' => 'tbl_artists','alias' => 'Artist','conditions'=> array('Artist.id = ArtistsSong.artist_id') ),array( 'table' => 'tbl_song_views','alias' => 'SongViews','type' => 'left','conditions'=> array('SongViews.song_id = ArtistsSong.song_id') ),),'order' => array('Artist.name'=>'asc') );
这是CakePHP中的一个错误.
但是,有一个诀窍来做到这一点.
您应该在主模型中添加一个虚拟字段.
假设你的主要模式是歌曲,你应该在调用分页之前添加它:
$this->Song->virtualFields = array( 'artist_name' => 'Artist.name' );
现在,您可以按artist_name排序.