我尝试了以下方法,但无法对其进行排序。
$options = array(
'limit' => $limit,
'offset' => $this->Account->get_offset($page, $limit),
'fields' => array(
'Accounts.login',
'Accounts.name',
'Accounts.created',
'COUNT(DISTINCT(Buyer.id)) AS "Accounts__buyer_count"',
'COUNT(DISTINCT(Seller.id)) AS "Accounts__seller_count"',
'COUNT(DISTINCT(Certificate.id)) AS "Accounts__certificate_count"'
),
'joins' => array(
array(
'table' => 'buyers',
'alias' => 'Buyer',
'type' => 'LEFT',
'conditions' => array('Buyer.account_id = Accounts.id')
),
array(
'table' => 'sellers',
'alias' => 'Seller',
'type' => 'LEFT',
'conditions' => array('Seller.buyer_id = Buyer.id')
),
array(
'table' => 'certificates',
'alias' => 'Certificate',
'type' => 'LEFT',
'conditions' => array('Certificate.buyer_id = Buyer.id')
)
),
'group' => array('Accounts.id'),
'order' => array('Accounts__certificate_count' => 'ASC')
);