I have two table dataset_type and type, now in the type model, I want to create CActiveDataProvider and use CDbCriteria in sql is
select type.name, type.description , count(dataset_type.dataset_id) as number
from type ,dataset_type
where type.id=dataset_type.type_id
group by type.id
How can i write by CDbCriteria
I try to write
$criteria=new CDbCriteria;
$criteria->select='type.name, type.description, count(dataset_type.dataset_id) as number';
$criteria->join='LEFT JOIN dataset_type ON dataset_type.type_id=id';
$criteria->group='type.id';
//$criteria->compare('id',$this->id);
//$criteria->compare('LOWER(name)',strtolower($this->name) , true);
//$criteria->compare('LOWER(description)',strtolower($this->description) , true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
but it shows error
CDbCommand failed to execute the SQL statement: SQLSTATE[42702]: Ambiguous column: 7 ERROR: column reference "id" is ambiguous at character 163. The SQL statement executed was:
SELECT COUNT(*)
FROM (SELECT type.name, type.description, count(dataset_type.dataset_id) as number
FROM "type" "t"
LEFT JOIN dataset_type ON dataset_type.type_id=id
GROUP BY type.id) sq