{"record":{"id":"ffc907bd953974d0","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-asenum-with-expr-other-than","errorCode":null,"errorMessage":"cannot apply alias for AsEnum with expr other than Column","messagePattern":"cannot apply alias for AsEnum with expr other than Column","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/query/combine.rs","lineNumber":69,"sourceCode":"                    sel.alias = Some(alias.into_iden());\n                }\n                None => {\n                    let col = match &sel.expr {\n                        SimpleExpr::Column(col_ref) => match col_ref.column() {\n                            Some(col) => col,\n                            None => {\n                                panic!(\"cannot apply alias for Column with asterisk\");\n                            }\n                        },\n                        SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {\n                            SimpleExpr::Column(col_ref) => match col_ref.column() {\n                                Some(col) => col,\n                                None => {\n                                    panic!(\"cannot apply alias for AsEnum with asterisk\")\n                                }\n                            },\n                            _ => {\n                                panic!(\"cannot apply alias for AsEnum with expr other than Column\")\n                            }\n                        },\n                        _ => panic!(\"cannot apply alias for expr other than Column or AsEnum\"),\n                    };\n                    let alias = format!(\"{}{}\", pre, col.to_string().as_str());\n                    sel.alias = Some(alias.into_iden());\n                }\n            };\n        });\n        self\n    }\n\n    /// Selects extra Entity and returns it together with the Entity from `Self`\n    pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>\n    where\n        F: EntityTrait,\n    {\n        self = self.apply_alias(SelectA.as_str());","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/query/combine.rs#L51-L87","documentation":"`apply_alias` prefixes each selected column with a table alias when building combined (`select_also`/`select_with`) queries. When the expression is `SimpleExpr::AsEnum`, only an inner `SimpleExpr::Column` can be translated into a column identifier for aliasing; any other inner expression (function, subquery, value, binary op) has no single column name, so the library panics with this message.","triggerScenarios":"Calling `select_also`, `select_also_fake`, `select_with`, `select_two_required`, or `left_join_linked` where a selected expression is `AsEnum` wrapping something other than a plain column — e.g. `.column_as(Expr::cast_as(...).into_column_with_enum(...))`, an AsEnum built over a function call or CASE expression, or a custom select expression typed as an enum.","commonSituations":"Using `column_as` with a computed expression whose return type is an ActiveEnum/DeriveValueType enum in a joined/combined query; migrating a simple find() query to `select_also` and discovering aliasing no longer supports the enum-wrapped expression.","solutions":["Move the AsEnum wrapper to a bare column: select the raw column via `.column(entity::COLUMN.col)` and convert to the enum in the model/after-fetch instead of in SQL.","If a computed expression is required, alias it manually with `.column_as(expr, \"alias\")` and avoid going through select_also's automatic aliasing, or restructure so the expression is not AsEnum-wrapped.","Split the query: run the enum conversion on a plain `Entity::find()` query, and keep select_also/select_with for plain-column entities only.","Check the sea-orm version — newer versions relaxed some aliasing cases; upgrade if a plain-column AsEnum is what you're actually passing."],"exampleFix":"// before\nlet rows = user::Entity::find()\n    .column_as(Expr::val(\"admin\").into_column_with_enum::<Role>(), \"u_role\") // AsEnum over non-Column\n    .select_also(profile::Entity)\n    .into_model::<(User, Option<Profile>)>()\n    .one(db).await?;\n\n// after: select the raw column, convert in Rust\nlet rows = user::Entity::find()\n    .column(user::COLUMN.role)\n    .select_also(profile::Entity)\n    .into_model::<(User, Option<Profile>)>()\n    .one(db).await?;","handlingStrategy":"validation","validationCode":"// Validate select items before calling select_also/select_with\nfn aliasable(expr: &SimpleExpr) -> bool {\n    match expr {\n        SimpleExpr::Column(_) => true,\n        SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(_)),\n        _ => false,\n    }\n}","typeGuard":"fn is_as_enum_over_column(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::AsEnum(_, inner) if matches!(inner.as_ref(), SimpleExpr::Column(_)))\n}","tryCatchPattern":null,"preventionTips":["Only attach enum (AsEnum) typing to bare columns via `.column(entity::COLUMN.col)`; convert computed values to enums in Rust after fetching.","Avoid `column_as` with expressions returning enum types inside combined/join selects.","Keep select_also/select_with queries to plain column selects; use separate raw queries for computed/converted values."],"tags":["panic","seaorm","query-builder","select-alias","enum-column"],"backgroundTag":"unsupported-operation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}