Concatenating and counting fields in CakePHP

I am trying to find count and concatinate what the count is in my field, but it gives an error since it cannot find make_count and I created the same field above.

$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')
            )
));

      

+3


source to share


1 answer


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')
            )
));

      



+1


source







All Articles