Свойство CDbCriteria.:centerId не определено в yii - PullRequest
0 голосов
/ 19 июня 2020

Я использую метод выбора в yii, он выдает ошибку «Свойство« CDbCriteria.:centerId »не определено»

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');
}

1 Ответ

1 голос
/ 19 июня 2020

Вы неправильно используете этот метод. Вы пропустили первый аргумент, который должен быть списком аргументов активной записи, используемых в качестве фильтра ( см. Документацию ). Вероятно, вам понадобится что-то вроде:

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

Или используйте 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');
}
...