diff --git a/examples/axum_example/entity/src/post.rs b/examples/axum_example/entity/src/post.rs index 76d78196..66a7b652 100644 --- a/examples/axum_example/entity/src/post.rs +++ b/examples/axum_example/entity/src/post.rs @@ -14,13 +14,7 @@ pub struct Model { pub text: String, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/graphql_example/entity/src/note.rs b/examples/graphql_example/entity/src/note.rs index 46f0c49b..a03f6d3f 100644 --- a/examples/graphql_example/entity/src/note.rs +++ b/examples/graphql_example/entity/src/note.rs @@ -13,15 +13,9 @@ pub struct Model { pub text: String, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {} impl Entity { diff --git a/issues/471/src/post.rs b/issues/471/src/post.rs index 3bb4d6a3..1e2e6046 100644 --- a/issues/471/src/post.rs +++ b/issues/471/src/post.rs @@ -14,13 +14,7 @@ pub struct Model { pub text: String, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/630/src/entity/underscores.rs b/issues/630/src/entity/underscores.rs index ddd0be85..4dd20ac1 100644 --- a/issues/630/src/entity/underscores.rs +++ b/issues/630/src/entity/underscores.rs @@ -15,15 +15,9 @@ pub struct Model { pub aa_b_c_d: i32, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {} #[cfg(test)] diff --git a/issues/630/src/entity/underscores_workaround.rs b/issues/630/src/entity/underscores_workaround.rs index 6773ad15..68cc0108 100644 --- a/issues/630/src/entity/underscores_workaround.rs +++ b/issues/630/src/entity/underscores_workaround.rs @@ -20,15 +20,9 @@ pub struct Model { pub aa_b_c_d: i32, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {} #[cfg(test)] diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 19722e18..f9d6c754 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -282,16 +282,8 @@ impl EntityWriter { let mut code_blocks = vec![ imports, Self::gen_compact_model_struct(entity, with_serde, date_time_crate, schema_name), + Self::gen_compact_relation_enum(entity), ]; - let relation_defs = if entity.get_relation_enum_name().is_empty() { - vec![ - Self::gen_relation_enum(entity), - Self::gen_impl_relation_trait(entity), - ] - } else { - vec![Self::gen_compact_relation_enum(entity)] - }; - code_blocks.extend(relation_defs); code_blocks.extend(Self::gen_impl_related(entity)); code_blocks.extend(Self::gen_impl_conjunct_related(entity)); code_blocks.extend(vec![Self::gen_impl_active_model_behavior()]); diff --git a/sea-orm-codegen/tests/compact/filling.rs b/sea-orm-codegen/tests/compact/filling.rs index dfedb1a7..de92558e 100644 --- a/sea-orm-codegen/tests/compact/filling.rs +++ b/sea-orm-codegen/tests/compact/filling.rs @@ -10,15 +10,9 @@ pub struct Model { pub name: String, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl Related for Entity { fn to() -> RelationDef { super::cake_filling::Relation::Cake.def() diff --git a/sea-orm-codegen/tests/compact_with_schema_name/filling.rs b/sea-orm-codegen/tests/compact_with_schema_name/filling.rs index 94795811..ead70acd 100644 --- a/sea-orm-codegen/tests/compact_with_schema_name/filling.rs +++ b/sea-orm-codegen/tests/compact_with_schema_name/filling.rs @@ -10,15 +10,9 @@ pub struct Model { pub name: String, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl Related for Entity { fn to() -> RelationDef { super::cake_filling::Relation::Cake.def() diff --git a/src/tests_cfg/lunch_set.rs b/src/tests_cfg/lunch_set.rs index b063245e..c0665da5 100644 --- a/src/tests_cfg/lunch_set.rs +++ b/src/tests_cfg/lunch_set.rs @@ -11,13 +11,7 @@ pub struct Model { pub tea: Tea, } -#[derive(Copy, Clone, Debug, EnumIter)] +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - impl ActiveModelBehavior for ActiveModel {}