{"record":{"id":"30ffdb4d46cd218e","repo":"SeaQL/sea-orm","slug":"cannot-apply-alias-for-asenum-with-expr-other-than-30ffdb","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":"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/src/query/combine.rs#L51-L87","documentation":"apply_alias only understands two shapes of select expressions: a bare Column and a Column wrapped in AsEnum. Any other expression type (function call, case, sub-query, binary op, etc.) cannot be aliased by the combinator, so it panics. This is a deliberate restriction of the select_also/select_with family.","triggerScenarios":"Passing an arbitrary SimpleExpr (COUNT(*), CASE, arithmetic, Func expressions) into a select list used with select_also, select_with, select_two_required or left_join_linked.","commonSituations":"Developers composing aggregate or computed columns into a joined aliased query expecting automatic aliasing; migrating raw select_expr usage into the combinator API.","solutions":["Select only concrete columns (bare Column or AsEnum-wrapped Column) with these combinators","Compute derived expressions in a separate query or alias them explicitly with .expr_as(...) instead of relying on apply_alias","Post-process computed values in Rust rather than in the aliased select list"],"exampleFix":"// before\nquery.expr(Expr::cust(\"COUNT(*)\"));\nquery.select_also(post::Entity);\n// after\nquery.column(user::COLUMN.id);\nquery.select_also(post::Entity);","handlingStrategy":"validation","validationCode":"fn aliasable(expr: &SimpleExpr) -> bool {\n    match expr {\n        SimpleExpr::Column(c) => c.column().is_some(),\n        SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(_)),\n        _ => false,\n    }\n}","typeGuard":"fn is_column_like(expr: &SimpleExpr) -> bool {\n    matches!(expr, SimpleExpr::Column(_) | SimpleExpr::AsEnum(_, _))\n}","tryCatchPattern":"// guard before the combinator\nassert!(exprs.iter().all(aliasable), \"only Column / AsEnum(Column) exprs are aliasable here\");","preventionTips":["Keep combinator select lists to plain columns","Use .expr_as(expr, alias) for computed expressions","Document that select_also/select_with only support column selections"],"tags":["panic","query-builder","alias","sql"],"backgroundTag":"unsupported-operation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}