@@ -4,7 +4,8 @@ pub use chrono::offset::Utc;
44pub use common:: { bakery_chain:: * , setup:: * , TestContext } ;
55pub use rust_decimal:: prelude:: * ;
66pub use rust_decimal_macros:: dec;
7- pub use sea_orm:: { entity:: * , query:: * , DbErr , FromQueryResult } ;
7+ pub use sea_orm:: { entity:: * , query:: * , DbErr , DerivePartialModel , FromQueryResult } ;
8+ pub use sea_query:: { Alias , Expr , Func , SimpleExpr } ;
89pub use uuid:: Uuid ;
910
1011// Run the test locally:
@@ -66,6 +67,7 @@ pub async fn left_join() {
6667 . filter ( baker:: Column :: Name . contains ( "Baker 1" ) ) ;
6768
6869 let result = select
70+ . clone ( )
6971 . into_model :: < SelectResult > ( )
7072 . one ( & ctx. db )
7173 . await
@@ -74,6 +76,28 @@ pub async fn left_join() {
7476 assert_eq ! ( result. name. as_str( ) , "Baker 1" ) ;
7577 assert_eq ! ( result. bakery_name, Some ( "SeaSide Bakery" . to_string( ) ) ) ;
7678
79+ #[ derive( DerivePartialModel , FromQueryResult , Debug , PartialEq ) ]
80+ #[ sea_orm( entity = "Baker" ) ]
81+ struct PartialSelectResult {
82+ name : String ,
83+ #[ sea_orm( from_expr = "Expr::col((bakery::Entity, bakery::Column::Name))" ) ]
84+ bakery_name : Option < String > ,
85+ #[ sea_orm(
86+ from_expr = r#"SimpleExpr::FunctionCall(Func::upper(Expr::col((bakery::Entity, bakery::Column::Name))))"#
87+ ) ]
88+ bakery_name_upper : Option < String > ,
89+ }
90+
91+ let result = select
92+ . into_partial_model :: < PartialSelectResult > ( )
93+ . one ( & ctx. db )
94+ . await
95+ . unwrap ( )
96+ . unwrap ( ) ;
97+ assert_eq ! ( result. name. as_str( ) , "Baker 1" ) ;
98+ assert_eq ! ( result. bakery_name, Some ( "SeaSide Bakery" . to_string( ) ) ) ;
99+ assert_eq ! ( result. bakery_name_upper, Some ( "SEASIDE BAKERY" . to_string( ) ) ) ;
100+
77101 let select = baker:: Entity :: find ( )
78102 . left_join ( bakery:: Entity )
79103 . select_only ( )
0 commit comments