diff --git a/issues/892/Cargo.toml b/issues/892/Cargo.toml new file mode 100644 index 00000000..cb87d22a --- /dev/null +++ b/issues/892/Cargo.toml @@ -0,0 +1,17 @@ +[workspace] +# A separate workspace + +[package] +name = "sea-orm-issues-892" +version = "0.1.0" +authors = [] +edition = "2021" +publish = false + +[dependencies] +tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros"] } + +[dependencies.sea-orm] +path = "../../" # remove this line in your own project +features = ["runtime-tokio-rustls", "sqlx-sqlite", "macros"] +default-features = false diff --git a/issues/892/src/main.rs b/issues/892/src/main.rs new file mode 100644 index 00000000..68c24d6c --- /dev/null +++ b/issues/892/src/main.rs @@ -0,0 +1,19 @@ +use sea_orm::tests_cfg::{cake, cake_filling}; +use sea_orm::{Database, DbErr, EntityTrait, JoinType, QuerySelect, RelationTrait}; + +#[tokio::main] +async fn main() -> Result<(), DbErr> { + let db = Database::connect("sqlite::memory:").await?; + + tokio::spawn(async move { + let _cakes = cake::Entity::find() + .join_rev(JoinType::InnerJoin, cake_filling::Relation::Cake.def()) + .all(&db) + .await + .unwrap(); + }) + .await + .unwrap(); + + Ok(()) +} diff --git a/src/entity/relation.rs b/src/entity/relation.rs index f4723352..40b2140a 100644 --- a/src/entity/relation.rs +++ b/src/entity/relation.rs @@ -62,7 +62,7 @@ pub struct RelationDef { /// `UPDATE` Operation is performed pub on_update: Option, /// Custom join ON condition - pub on_condition: Option Condition>>, + pub on_condition: Option Condition + Send + Sync>>, /// The name of foreign key constraint pub fk_name: Option, } @@ -85,7 +85,7 @@ impl std::fmt::Debug for RelationDef { fn debug_on_condition( d: &mut core::fmt::DebugStruct<'_, '_>, - on_condition: &Option Condition>>, + on_condition: &Option Condition + Send + Sync>>, ) { match on_condition { Some(func) => { @@ -118,7 +118,7 @@ where is_owner: bool, on_delete: Option, on_update: Option, - on_condition: Option Condition>>, + on_condition: Option Condition + Send + Sync>>, fk_name: Option, } @@ -190,7 +190,7 @@ impl RelationDef { /// ); pub fn on_condition(mut self, f: F) -> Self where - F: Fn(DynIden, DynIden) -> Condition + 'static, + F: Fn(DynIden, DynIden) -> Condition + 'static + Send + Sync, { self.on_condition = Some(Box::new(f)); self @@ -270,7 +270,7 @@ where /// denoting the left-hand side and right-hand side table in the join expression. pub fn on_condition(mut self, f: F) -> Self where - F: Fn(DynIden, DynIden) -> Condition + 'static, + F: Fn(DynIden, DynIden) -> Condition + 'static + Send + Sync, { self.on_condition = Some(Box::new(f)); self @@ -303,3 +303,19 @@ where } } } + +#[cfg(test)] +mod tests { + use crate::{ + tests_cfg::{cake, fruit}, + RelationBuilder, RelationDef, + }; + + #[test] + fn assert_relation_traits() { + fn assert_send_sync() {} + + assert_send_sync::(); + assert_send_sync::>(); + } +}