use sea_orm::entity::prelude::*; #[derive(Copy, Clone, Default, Debug, DeriveEntity)] pub struct Entity; impl EntityName for Entity { fn table_name(&self) -> &str { "cake" } } #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] pub struct Model { pub id: i32, pub name: String, pub price: Decimal, pub bakery_id: Option, pub gluten_free: bool, pub serial: Uuid, } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] pub enum Column { Id, Name, Price, BakeryId, GlutenFree, Serial, } #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] pub enum PrimaryKey { Id, } impl PrimaryKeyTrait for PrimaryKey { fn auto_increment() -> bool { true } } #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { Bakery, Lineitem, } 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::Price => ColumnType::Decimal(Some((19, 4))).def(), Self::BakeryId => ColumnType::Integer.def(), Self::GlutenFree => ColumnType::Boolean.def(), Self::Serial => ColumnType::String(None).def(), } } } impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { Self::Bakery => Entity::belongs_to(super::bakery::Entity) .from(Column::BakeryId) .to(super::bakery::Column::Id) .into(), Self::Lineitem => Entity::has_many(super::lineitem::Entity).into(), } } } impl Related for Entity { fn to() -> RelationDef { Relation::Bakery.def() } } impl Related for Entity { fn to() -> RelationDef { super::cakes_bakers::Relation::Baker.def() } fn via() -> Option { Some(super::cakes_bakers::Relation::Cake.def().rev()) } } impl Related for Entity { fn to() -> RelationDef { Relation::Lineitem.def() } } impl ActiveModelBehavior for ActiveModel {}