Added QuerySelect::tbl_col_as
This commit is contained in:
parent
a9c2e1bd0b
commit
1cdbbd4025
@ -528,7 +528,7 @@ pub trait QuerySelect: Sized {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Owned version of `expr_as`.
|
/// Same of `expr_as`. Here for legacy reasons.
|
||||||
///
|
///
|
||||||
/// Select column.
|
/// Select column.
|
||||||
///
|
///
|
||||||
@ -555,6 +555,32 @@ pub trait QuerySelect: Sized {
|
|||||||
self.query().expr_as(expr, alias.into_identity());
|
self.query().expr_as(expr, alias.into_identity());
|
||||||
self
|
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<T, C, A>(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
|
// LINT: when the column does not appear in tables selected from
|
||||||
|
Loading…
x
Reference in New Issue
Block a user