self::OP_ALL ]; } /** * @return ActiveQuery */ public static function find() { return Yii::createObject(ActiveQuery::className(), [get_called_class()]); } /** * @param $condition * @return static|array|null */ public static function findOneOrFail($condition) { return static::findByCondition($condition)->oneOrFail(); } protected static function findByCondition($condition) { $query = static::find(); if (!ArrayHelper::isAssociative($condition)) { // query by primary key $primaryKey = static::primaryKey(); if (isset($primaryKey[0])) { $pk = $primaryKey[0]; if (!empty($query->join) || !empty($query->joinWith)) { $pk = static::tableName() . '.' . $pk; } $condition = [$pk => $condition]; } else { throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.'); } } return $query->andWhere($condition); } }