0
我有2個表視圖和視圖。視頻有很多觀點。我運行此查詢:對cakephp 3中關聯的計算字段進行排序
$query = $this->Videos->find('all');
$query->select([
'id',
'title',
'user_id',
'purchase_count',
'created',
'price',
'total_price'=>$query->newExpr()->add('price*purchase_count'),
'created'
])->distinct();
$query->contain([
'Views'=>function($v)use($from,$to){
return $v->select([
'id',
'video_id',
'free_views_total'=>$v->func()->sum('free_views'),
'subscription_view_total'=>$v->func()->sum('subscription_view')
])
->where([
'Views.created >='=>$from,'Views.created <='=>$to])->group('video_id');
}]);
$this->paginate=[
'sortWhitelist' => [
'id',
'title',
'user_id',
'Views.free_views_total',
'Views.subscription_view_total',
'purchase_count',
'price',
'total_price',
'created'
]];
此查詢工作正常,但我不能夠通過free_views_total
和subscription_view_total
進行排序。我還在sortWhitelist
中添加了這些內容。但它也不起作用。請幫忙。提前致謝。