{"record":{"id":"7643407adda49e08","repo":"yiisoft/yii2","slug":"to-use-expression-in-from-method-pass-it-in-arr","errorCode":null,"errorMessage":"To use Expression in from() method, pass it in array format with alias.","messagePattern":"To use Expression in from\\(\\) method, pass it in array format with alias\\.","errorType":"exception","errorClass":"yii\\base\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/db/Query.php","lineNumber":591,"sourceCode":")\n)?\n\\s*\n$\n~iux\nPATTERN;\n                if (preg_match($pattern, $tableName, $matches)) {\n                    if (isset($matches[2])) {\n                        list(, $tableName, $alias) = $matches;\n                    } else {\n                        $tableName = $alias = $matches[1];\n                    }\n                }\n            }\n\n\n            if ($tableName instanceof Expression) {\n                if (!is_string($alias)) {\n                    throw new InvalidArgumentException('To use Expression in from() method, pass it in array format with alias.');\n                }\n                $cleanedUpTableNames[$this->ensureNameQuoted($alias)] = $tableName;\n            } elseif ($tableName instanceof self) {\n                $cleanedUpTableNames[$this->ensureNameQuoted($alias)] = $tableName;\n            } else {\n                $cleanedUpTableNames[$this->ensureNameQuoted($alias)] = $this->ensureNameQuoted($tableName);\n            }\n        }\n\n        return $cleanedUpTableNames;\n    }\n\n    /**\n     * Ensures name is wrapped with {{ and }}\n     * @param string $name\n     * @return string\n     */\n    private function ensureNameQuoted($name)","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/Query.php#L573-L609","documentation":"Error \"To use Expression in from() method, pass it in array format with alias.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/Query.php:591 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}