From f75fcd8fdf42bd47307257be5473eec259fa374e Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 20 Jul 2021 11:48:19 +0800 Subject: [PATCH] Update unit test --- examples/cli/src/entity/cake.rs | 17 +++++++++-------- examples/cli/src/entity/filling.rs | 13 +++++++------ examples/codegen/src/entity/cake.rs | 17 +++++++++-------- examples/codegen/src/entity/filling.rs | 13 +++++++------ sea-orm-codegen/tests/entity/cake.rs | 17 +++++++++-------- sea-orm-codegen/tests/entity/filling.rs | 13 +++++++------ 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/examples/cli/src/entity/cake.rs b/examples/cli/src/entity/cake.rs index 12e7c4ab..29f55ac6 100644 --- a/examples/cli/src/entity/cake.rs +++ b/examples/cli/src/entity/cake.rs @@ -36,7 +36,6 @@ impl PrimaryKeyTrait for PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { - CakeFilling, Fruit, } @@ -53,22 +52,24 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), Self::Fruit => Entity::has_many(super::fruit::Entity).into(), } } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::CakeFilling.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::Fruit.def() } } +impl Related for Entity { + fn to() -> RelationDef { + super::cake_filling::Relation::Filling.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Cake.def().rev()) + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/cli/src/entity/filling.rs b/examples/cli/src/entity/filling.rs index 752317a4..bedb1ab4 100644 --- a/examples/cli/src/entity/filling.rs +++ b/examples/cli/src/entity/filling.rs @@ -35,9 +35,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - CakeFilling, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -52,14 +50,17 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), + _ => panic!("No RelationDef"), } } } -impl Related for Entity { +impl Related for Entity { fn to() -> RelationDef { - Relation::CakeFilling.def() + super::cake_filling::Relation::Cake.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Filling.def().rev()) } } diff --git a/examples/codegen/src/entity/cake.rs b/examples/codegen/src/entity/cake.rs index 12e7c4ab..29f55ac6 100644 --- a/examples/codegen/src/entity/cake.rs +++ b/examples/codegen/src/entity/cake.rs @@ -36,7 +36,6 @@ impl PrimaryKeyTrait for PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { - CakeFilling, Fruit, } @@ -53,22 +52,24 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), Self::Fruit => Entity::has_many(super::fruit::Entity).into(), } } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::CakeFilling.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::Fruit.def() } } +impl Related for Entity { + fn to() -> RelationDef { + super::cake_filling::Relation::Filling.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Cake.def().rev()) + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/examples/codegen/src/entity/filling.rs b/examples/codegen/src/entity/filling.rs index 752317a4..bedb1ab4 100644 --- a/examples/codegen/src/entity/filling.rs +++ b/examples/codegen/src/entity/filling.rs @@ -35,9 +35,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - CakeFilling, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -52,14 +50,17 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), + _ => panic!("No RelationDef"), } } } -impl Related for Entity { +impl Related for Entity { fn to() -> RelationDef { - Relation::CakeFilling.def() + super::cake_filling::Relation::Cake.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Filling.def().rev()) } } diff --git a/sea-orm-codegen/tests/entity/cake.rs b/sea-orm-codegen/tests/entity/cake.rs index 12e7c4ab..29f55ac6 100644 --- a/sea-orm-codegen/tests/entity/cake.rs +++ b/sea-orm-codegen/tests/entity/cake.rs @@ -36,7 +36,6 @@ impl PrimaryKeyTrait for PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { - CakeFilling, Fruit, } @@ -53,22 +52,24 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), Self::Fruit => Entity::has_many(super::fruit::Entity).into(), } } } -impl Related for Entity { - fn to() -> RelationDef { - Relation::CakeFilling.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::Fruit.def() } } +impl Related for Entity { + fn to() -> RelationDef { + super::cake_filling::Relation::Filling.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Cake.def().rev()) + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/sea-orm-codegen/tests/entity/filling.rs b/sea-orm-codegen/tests/entity/filling.rs index 752317a4..bedb1ab4 100644 --- a/sea-orm-codegen/tests/entity/filling.rs +++ b/sea-orm-codegen/tests/entity/filling.rs @@ -35,9 +35,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - CakeFilling, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -52,14 +50,17 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { - Self::CakeFilling => Entity::has_many(super::cake_filling::Entity).into(), + _ => panic!("No RelationDef"), } } } -impl Related for Entity { +impl Related for Entity { fn to() -> RelationDef { - Relation::CakeFilling.def() + super::cake_filling::Relation::Cake.def() + } + fn via() -> Option { + Some(super::cake_filling::Relation::Filling.def().rev()) } }