Cakephp中的Concatinating和Counting字段

时间:2015-07-28 12:04:36

标签: cakephp count virtual

我试图在我的字段中找到计数和concatinate但是它给出了错误消息,因为找不到make_count并且我在上面创建了相同的字段。

$this->Car->virtualFields['make_count'] = 'COUNT(Car.car_make)';
$this->Car->virtualFields['make_concat']='CONCAT(Car.car_make,Car.make_count)';

$models = array_unique($this->Car->find('list',array(  
                'fields' => array('Car.car_make', 'Car.make_concat'),
                'conditions'=>array('Car.ad_status'=>'saved'),
                'order'=>array('Car.car_make'=>'Asc'),
                'contain'=>false,
                'group'=>array('Car.car_make')
            )
));

1 个答案:

答案 0 :(得分:1)

Try:
$this->Car->virtualFields['make_concat']='CONCAT(Car.car_make,COUNT(Car.car_make))';

$models = array_unique($this->Car->find('list',array(  
                'fields' => array('Car.car_make', 'Car.make_concat'),
                'conditions'=>array('Car.ad_status'=>'saved'),
                'order'=>array('Car.car_make'=>'Asc'),
                'contain'=>false,
                'group'=>array('Car.car_make')
            )
));