Answer the question
In order to leave comments, you need to log in
Why might count in a model not work correctly in Yii?
I make a simple request:
$criteria = new CDbCriteria();
$criteria->addCondition('t.user_id = :uid OR company.id IN (:cid)');
$criteria->with = array('company' => array('select' => 'Name'));
$criteria->params = array(':uid' => Yii::app()->user->id, ':cid' => implode(', ', $arCID));
Bill::model()->count($criteria)
SELECT COUNT(DISTINCT `t`.`id`) FROM `o_bills` `t` LEFT OUTER JOIN `o_company` `company` ON (`t`.`companyId`=`company`.`id`) WHERE (t.user_id = :uid OR company.id IN (:cid))
$criteria = new CDbCriteria();
$criteria->addInCondition('company.id', $arCID);
$criteria->addCondition('t.user_id = :uid', 'OR')->params[':uid'] = Yii::app()->user->id;
$criteria->with = array('company' => array('select' => 'Name'));
Answer the question
In order to leave comments, you need to log in
Yii does not count the number of raw rows returned, but the number of Bill models returned.
as an option, not all records in the database have fields filled in, which are indicated as mandatory in the model. In this case, the framework will ignore them, as far as I remember.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question