public function countByAttributes($attributes, $condition = '', $params = array()) { $prefix = $this->getTableAlias(true) . '.'; $builder = $this->getCommandBuilder(); $criteria = $builder->createColumnCriteria($this->getTableSchema(), $attributes, $condition, $params, $prefix); $this->applyScopes($criteria); if (empty($criteria->with)) { return $builder->createCountCommand($this->getTableSchema(), $criteria)->queryScalar(); } else { $finder = new CActiveFinder($this, $criteria->with); return $finder->count($criteria); } }
public function exists($condition = '', $params = array()) { $builder = $this->getCommandBuilder(); $criteria = $builder->createCriteria($condition, $params); $table = $this->getTableSchema(); $criteria->select = '1'; $criteria->limit = 1; $this->applyScopes($criteria); if (empty($criteria->with)) { return $builder->createFindCommand($table, $criteria)->queryRow() !== false; } else { $criteria->select = '*'; $finder = new CActiveFinder($this, $criteria->with); return $finder->count($criteria) > 0; } }
/** * Checks whether there is row satisfying the specified condition. * See {@link find()} for detailed explanation about $condition and $params. * @param mixed $condition query condition or criteria. * @param array $params parameters to be bound to an SQL statement. * @return boolean whether there is row satisfying the specified condition. */ public function exists($condition = '', $params = array()) { Yii::trace(get_class($this) . '.exists()', 'system.db.ar.CActiveRecord'); $builder = $this->getCommandBuilder(); $criteria = $builder->createCriteria($condition, $params); $table = $this->getTableSchema(); $criteria->select = '1'; $criteria->limit = 1; $this->applyScopes($criteria); if (empty($criteria->with)) { return $builder->createFindCommand($table, $criteria, $this->getTableAlias(false, false))->queryRow() !== false; } else { $criteria->select = '*'; $finder = new CActiveFinder($this, $criteria->with); return $finder->count($criteria) > 0; } }