SeaQL/sea-orm · error
cannot apply alias for AsEnum with expr other than Column
Error message
cannot apply alias for AsEnum with expr other than Column
What it means
`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.
Source
Thrown at sea-orm-sync/src/query/combine.rs:69
sel.alias = Some(alias.into_iden());
}
None => {
let col = match &sel.expr {
SimpleExpr::Column(col_ref) => match col_ref.column() {
Some(col) => col,
None => {
panic!("cannot apply alias for Column with asterisk");
}
},
SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {
SimpleExpr::Column(col_ref) => match col_ref.column() {
Some(col) => col,
None => {
panic!("cannot apply alias for AsEnum with asterisk")
}
},
_ => {
panic!("cannot apply alias for AsEnum with expr other than Column")
}
},
_ => panic!("cannot apply alias for expr other than Column or AsEnum"),
};
let alias = format!("{}{}", pre, col.to_string().as_str());
sel.alias = Some(alias.into_iden());
}
};
});
self
}
/// Selects extra Entity and returns it together with the Entity from `Self`
pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>
where
F: EntityTrait,
{
self = self.apply_alias(SelectA.as_str());View on GitHub (pinned to e29bcd1b41)
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.
Example fix
// before
let rows = user::Entity::find()
.column_as(Expr::val("admin").into_column_with_enum::<Role>(), "u_role") // AsEnum over non-Column
.select_also(profile::Entity)
.into_model::<(User, Option<Profile>)>()
.one(db).await?;
// after: select the raw column, convert in Rust
let rows = user::Entity::find()
.column(user::COLUMN.role)
.select_also(profile::Entity)
.into_model::<(User, Option<Profile>)>()
.one(db).await?; Defensive patterns
Strategy: validation
Validate before calling
// Validate select items before calling select_also/select_with
fn aliasable(expr: &SimpleExpr) -> bool {
match expr {
SimpleExpr::Column(_) => true,
SimpleExpr::AsEnum(_, inner) => matches!(inner.as_ref(), SimpleExpr::Column(_)),
_ => false,
}
} Type guard
fn is_as_enum_over_column(expr: &SimpleExpr) -> bool {
matches!(expr, SimpleExpr::AsEnum(_, inner) if matches!(inner.as_ref(), SimpleExpr::Column(_)))
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- cannot apply alias for AsEnum with asterisk
- cannot apply alias for expr other than Column or AsEnum
- Not mock connection
- Not proxy connection
- cannot apply alias for Column with asterisk
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/ffc907bd953974d0.
Report an issue: GitHub.