Sat*_*abu 15 sorting pagination cakephp join
具有连接表排序的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')
);
Run Code Online (Sandbox Code Playgroud)
ant*_*oyo 20
这是CakePHP中的一个错误.
但是,有一个技巧可以做到这一点.
您应该在主模型中添加虚拟字段.
假设你的主要模型是Song,你应该在调用paginate之前添加它:
$this->Song->virtualFields = array(
'artist_name' => 'Artist.name'
);
Run Code Online (Sandbox Code Playgroud)
而现在,你可以排序artist_name
.