diff --git a/src/entity/column.rs b/src/entity/column.rs index 92d83a65..e2ade89b 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -315,17 +315,28 @@ impl ColumnTypeTrait for ColumnType { } fn get_enum_name(&self) -> Option<&DynIden> { - fn enum_name(col_type: &ColumnType) -> Option<&DynIden> { - match col_type { - ColumnType::Enum { name, .. } => Some(name), - ColumnType::Array(col_type) => enum_name(col_type), - _ => None, - } - } enum_name(self) } } +impl ColumnTypeTrait for ColumnDef { + fn def(self) -> ColumnDef { + self + } + + fn get_enum_name(&self) -> Option<&DynIden> { + enum_name(&self.col_type) + } +} + +fn enum_name(col_type: &ColumnType) -> Option<&DynIden> { + match col_type { + ColumnType::Enum { name, .. } => Some(name), + ColumnType::Array(col_type) => enum_name(col_type), + _ => None, + } +} + impl ColumnDef { /// Marks the column as `UNIQUE` pub fn unique(mut self) -> Self { diff --git a/src/tests_cfg/lunch_set_expanded.rs b/src/tests_cfg/lunch_set_expanded.rs new file mode 100644 index 00000000..c15bb59c --- /dev/null +++ b/src/tests_cfg/lunch_set_expanded.rs @@ -0,0 +1,64 @@ +use super::sea_orm_active_enums::*; +use crate as sea_orm; +use crate::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "lunch_set" + } +} + +#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)] +#[sea_orm(table_name = "lunch_set")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub name: String, + pub tea: Tea, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + Id, + Name, + Tea, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + Id, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl ColumnTrait for Column { + type EntityName = Entity; + + fn def(&self) -> ColumnDef { + match self { + Self::Id => ColumnType::Integer.def(), + Self::Name => ColumnType::String(None).def(), + Self::Tea => Tea::db_type().def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/tests_cfg/mod.rs b/src/tests_cfg/mod.rs index 9210657c..a83475eb 100644 --- a/src/tests_cfg/mod.rs +++ b/src/tests_cfg/mod.rs @@ -9,6 +9,7 @@ pub mod filling; pub mod fruit; pub mod indexes; pub mod lunch_set; +pub mod lunch_set_expanded; pub mod rust_keyword; pub mod sea_orm_active_enums; pub mod vendor; @@ -20,5 +21,6 @@ pub use cake_filling_price::Entity as CakeFillingPrice; pub use filling::Entity as Filling; pub use fruit::Entity as Fruit; pub use lunch_set::Entity as LunchSet; +pub use lunch_set_expanded::Entity as LunchSetExpanded; pub use rust_keyword::Entity as RustKeyword; pub use vendor::Entity as Vendor;