diff --git a/src/query/helper.rs b/src/query/helper.rs index 3a3e0c67d..c4154aa11 100644 --- a/src/query/helper.rs +++ b/src/query/helper.rs @@ -528,7 +528,7 @@ pub trait QuerySelect: Sized { self } - /// Owned version of `expr_as`. + /// Same of `expr_as`. Here for legacy reasons. /// /// Select column. /// @@ -555,6 +555,32 @@ pub trait QuerySelect: Sized { self.query().expr_as(expr, alias.into_identity()); self } + + /// Shorthand of `expr_as(Expr::col((T, C)), A)`. + /// + /// ``` + /// use sea_orm::sea_query::{Alias, Expr, Func}; + /// use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait}; + /// + /// assert_eq!( + /// cake::Entity::find() + /// .select_only() + /// .tbl_col_as((cake::Entity, cake::Column::Name), "cake_name") + /// .build(DbBackend::MySql) + /// .to_string(), + /// "SELECT `cake`.`name` AS `cake_name` FROM `cake`" + /// ); + /// ``` + fn tbl_col_as(mut self, (tbl, col): (T, C), alias: A) -> Self + where + T: IntoIden + 'static, + C: IntoIden + 'static, + A: IntoIdentity, + { + self.query() + .expr_as(Expr::col((tbl, col)), alias.into_identity()); + self + } } // LINT: when the column does not appear in tables selected from