use sea_orm::entity::prelude::*; #[derive(Copy, Clone, Default, Debug, DeriveEntity)] pub struct Entity; impl EntityName for Entity { fn table_name(&self) -> &str { "lineitem" } } #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] pub struct Model { pub id: i32, pub price: f32, pub quantity: i32, pub order_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] pub enum Column { Id, Price, Quantity, OrderId, } #[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 { Order, } impl ColumnTrait for Column { type EntityName = Entity; fn def(&self) -> ColumnDef { match self { Self::Id => ColumnType::Integer.def(), Self::Price => ColumnType::Money(Some((19, 4))).def(), Self::Quantity => ColumnType::Integer.def(), Self::OrderId => ColumnType::Integer.def(), } } } impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { Self::Order => Entity::belongs_to(super::order::Entity) .from(Column::Id) .to(super::order::Column::CustomerId) .into(), } } } impl Related for Entity { fn to() -> RelationDef { Relation::Order.def() } } impl ActiveModelBehavior for ActiveModel {}