diff --git a/tests/common/features/self_join.rs b/tests/common/features/self_join.rs index 933eff158..a3c809158 100644 --- a/tests/common/features/self_join.rs +++ b/tests/common/features/self_join.rs @@ -28,50 +28,3 @@ impl Linked for SelfReferencingLink { } impl ActiveModelBehavior for ActiveModel {} - -#[cfg(test)] -mod tests { - use super::*; - use pretty_assertions::assert_eq; - use sea_orm::*; - - #[test] - fn find_linked_001() { - let self_join_model = Model { - uuid: Uuid::default(), - uuid_ref: None, - time: None, - }; - - assert_eq!( - self_join_model - .find_linked(SelfReferencingLink) - .build(DbBackend::MySql) - .to_string(), - [ - r#"SELECT `self_join`.`uuid`, `self_join`.`uuid_ref`, `self_join`.`time`"#, - r#"FROM `self_join`"#, - r#"INNER JOIN `self_join` AS `r0` ON `r0`.`uuid_ref` = `self_join`.`uuid`"#, - r#"WHERE `r0`.`uuid` = '00000000-0000-0000-0000-000000000000'"#, - ] - .join(" ") - ); - } - - #[test] - fn find_also_linked_001() { - assert_eq!( - Entity::find() - .find_also_linked(SelfReferencingLink) - .build(DbBackend::MySql) - .to_string(), - [ - r#"SELECT `self_join`.`uuid` AS `A_uuid`, `self_join`.`uuid_ref` AS `A_uuid_ref`, `self_join`.`time` AS `A_time`,"#, - r#"`r0`.`uuid` AS `B_uuid`, `r0`.`uuid_ref` AS `B_uuid_ref`, `r0`.`time` AS `B_time`"#, - r#"FROM `self_join`"#, - r#"LEFT JOIN `self_join` AS `r0` ON `self_join`.`uuid_ref` = `r0`.`uuid`"#, - ] - .join(" ") - ); - } -} diff --git a/tests/self_join_tests.rs b/tests/self_join_tests.rs index afe444365..f35dd5050 100644 --- a/tests/self_join_tests.rs +++ b/tests/self_join_tests.rs @@ -2,7 +2,7 @@ pub mod common; pub use common::{features::*, setup::*, TestContext}; use pretty_assertions::assert_eq; -use sea_orm::{entity::prelude::*, IntoActiveModel, QueryOrder}; +use sea_orm::{entity::prelude::*, query::*, DbBackend, IntoActiveModel, QueryOrder}; #[sea_orm_macros::test] #[cfg(any( @@ -15,6 +15,8 @@ async fn main() -> Result<(), DbErr> { create_tables(&ctx.db).await?; create_metadata(&ctx.db).await?; ctx.delete().await; + find_linked_001(); + find_also_linked_001(); Ok(()) } @@ -87,3 +89,45 @@ pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { Ok(()) } + +fn find_linked_001() { + use self_join::*; + + let self_join_model = Model { + uuid: Uuid::default(), + uuid_ref: None, + time: None, + }; + + assert_eq!( + self_join_model + .find_linked(SelfReferencingLink) + .build(DbBackend::MySql) + .to_string(), + [ + r#"SELECT `self_join`.`uuid`, `self_join`.`uuid_ref`, `self_join`.`time`"#, + r#"FROM `self_join`"#, + r#"INNER JOIN `self_join` AS `r0` ON `r0`.`uuid_ref` = `self_join`.`uuid`"#, + r#"WHERE `r0`.`uuid` = '00000000-0000-0000-0000-000000000000'"#, + ] + .join(" ") + ); +} + +fn find_also_linked_001() { + use self_join::*; + + assert_eq!( + Entity::find() + .find_also_linked(SelfReferencingLink) + .build(DbBackend::MySql) + .to_string(), + [ + r#"SELECT `self_join`.`uuid` AS `A_uuid`, `self_join`.`uuid_ref` AS `A_uuid_ref`, `self_join`.`time` AS `A_time`,"#, + r#"`r0`.`uuid` AS `B_uuid`, `r0`.`uuid_ref` AS `B_uuid_ref`, `r0`.`time` AS `B_time`"#, + r#"FROM `self_join`"#, + r#"LEFT JOIN `self_join` AS `r0` ON `self_join`.`uuid_ref` = `r0`.`uuid`"#, + ] + .join(" ") + ); +}