Sampath Wijesinghe
Sampath Wijesinghe

Reputation: 690

Property "CDbCriteria.:centerId" is not defined in yii

I am using select method in yii it gives error "Property "CDbCriteria.:centerId" is not defined"

if (0 < self::model()->countByAttributes(
    'centerId = :centerId AND qTypeId = :qTypeId',
    array(
        ':centerId' => $centerId,
        ':qTypeId'  => $qTypeId,
    )
)) {
    throw new Exception('Duplicate Entry for center and que type');
}

Upvotes: 0

Views: 115

Answers (1)

rob006
rob006

Reputation: 22174

You're using this method in a wrong way. You skipped first argument, which should be list of active record arguments used as filter (see documentation). You probably need something like:

if (0 < self::model()->countByAttributes([
    'centerId' => $centerId,
    'qTypeId'  => $qTypeId,
]) {
    throw new Exception('Duplicate Entry for center and que type');
}

Or use count():

if (0 < self::model()->count(
    'centerId = :centerId AND qTypeId = :qTypeId',
    [
        ':centerId' => $centerId,
        ':qTypeId'  => $qTypeId,
    ]
)) {
    throw new Exception('Duplicate Entry for center and que type');
}

Upvotes: 1

Related Questions