diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index 7d72c67b..ee479171 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -353,6 +353,14 @@ impl ActiveEnum { <::Value as sea_orm::sea_query::Nullable>::null() } } + + #[automatically_derived] + impl std::fmt::Display for #ident { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let v: sea_orm::sea_query::Value = self.to_value().into(); + write!(f, "{}", v) + } + } ) } } diff --git a/src/entity/active_enum.rs b/src/entity/active_enum.rs index 19a48a1b..fb0a7c83 100644 --- a/src/entity/active_enum.rs +++ b/src/entity/active_enum.rs @@ -241,6 +241,9 @@ mod tests { DeriveCategory::name().to_string() ); assert_eq!(Category::values(), DeriveCategory::values()); + + assert_eq!(format!("{}", DeriveCategory::Big), "'B'"); + assert_eq!(format!("{}", DeriveCategory::Small), "'S'"); } #[test] @@ -295,6 +298,10 @@ mod tests { ); assert_eq!($ident::db_type(), ColumnType::$col_def.def()); + + assert_eq!(format!("{}", $ident::Big), "1"); + assert_eq!(format!("{}", $ident::Small), "0"); + assert_eq!(format!("{}", $ident::Negative), "-10"); }; } @@ -356,6 +363,9 @@ mod tests { ); assert_eq!($ident::db_type(), ColumnType::$col_def.def()); + + assert_eq!(format!("{}", $ident::Big), "1"); + assert_eq!(format!("{}", $ident::Small), "0"); }; }