class CDbCommandBuilder extends CComponent
{
......
public function createCountCommand($table,$criteria)
{
$this->ensureTable($table);
$c=new CDBCriteria;
$criteria->order=$c->order; //default
$criteria->limit=$c->limit;//default
$criteria->offset=$c->offset;//default
//return $this->createFindCommand($table,$criteria);
return 'select count(*) from ('.$this->createFindCommand($table,$criteria).') AS subquery_random_name;';
}
....
original
public function createCountCommand($table,$criteria)
{
$this->ensureTable($table);
$criteria->select='COUNT(*)';
return $this->createFindCommand($table,$criteria);
}
No entiendo mucho lo que quisiste hacer en el command builder, pero probaste esto (SIN modificar el command builder)
$columnas=array();
$columnas[]='DISTINCT(idProfesional)'; // EDITE ESTA LINEA
$columnas[]='estado';
$criteria->select=$columnas;
//$criteria->distinct=true; <-- ESTO NO LO PONGAS
$cantidad=Rp_profesionales::model()->count($criteria);
Yii::log($columnas[0], 'trace');
Yii::log($columnas[1], 'trace');
No lo probe, pero calculo que funciona. Igual, si lo probas, me pasarias el SQL resultante a ver que quedo de eso?
NOTA: Todo lo que esta en el core no deberias tocarlo. Poruqe si hacen alguna modificacion y vos actualizas el core perdes todos los cambios que hayas hecho. Siempre es mejor heredar (o mejor dicho subclasificar) y usar esas subclases que vos crees con la funcionalidad añadida/cambiada.
Active record "Rp_profesionales" esta intentando de seleccionar unacolumna inválida "DISTINCT(idProfesional)". Nota: La columna puedeexistir en la base o ser una expresion con alias.
The only thing I think we should be aware of is that the generated SQL is working in all DBMS. Also check the performance of this two options (auxiliary table creations, etc:
SELECT COUNT(distinct id, data) FROM tbl;
vs
SELECT COUNT(*) FROM (SELECT distinct id, data FROM tbl);
I think this is a better approach:
public function createCountCommand($table,$criteria)
{
$this->ensureTable($table);
if ($criteria->distinct){
$select=is_array($criteria->select) ? implode(', ',$criteria->select) : $criteria->select;
$criteria->select = 'COUNT (DISTINCT ' . $select . ')';
}else{
$criteria->select='COUNT(*)';
}
return $this->createFindCommand($table,$criteria);
}
Me olvide de decirte que el bug al que vos haces referencia tiene otro problema que es que no se usa el count como dice que debe ser usado y si devuelve lo que realmente debe devolver según mi opinión…
The only thing I think we should be aware of is that the generated SQL is working in all DBMS. Also check the performance of this two options (auxiliary table creations, etc:
SELECT COUNT(distinct id, data) FROM tbl;
vs
SELECT COUNT(*) FROM (SELECT distinct id, data FROM tbl);
[color="#0000ff"]You’re right[/color]
I think this is a better approach:
public function createCountCommand($table,$criteria)
{
$this->ensureTable($table);
if ($criteria->distinct){
$select=is_array($criteria->select) ? implode(', ',$criteria->select) : $criteria->select;
$criteria->select = 'COUNT (DISTINCT ' . $select . ')';
}else{
$criteria->select='COUNT(*)';
}
return $this->createFindCommand($table,$criteria);
}