103 lines
2.4 KiB
Rust
103 lines
2.4 KiB
Rust
use sea_orm::entity::prelude::*;
|
|
|
|
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
|
pub struct Entity;
|
|
|
|
impl EntityName for Entity {
|
|
fn table_name(&self) -> &str {
|
|
"order"
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
|
pub struct Model {
|
|
pub id: i32,
|
|
pub total: Decimal,
|
|
pub bakery_id: i32,
|
|
pub customer_id: i32,
|
|
pub placed_at: DateTime,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
Id,
|
|
Total,
|
|
BakeryId,
|
|
CustomerId,
|
|
PlacedAt,
|
|
}
|
|
|
|
#[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 {
|
|
Bakery,
|
|
Customer,
|
|
Lineitem,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::Id => ColumnType::Integer.def(),
|
|
Self::Total => ColumnType::Decimal(Some((19, 4))).def(),
|
|
Self::BakeryId => ColumnType::Integer.def(),
|
|
Self::CustomerId => ColumnType::Integer.def(),
|
|
Self::PlacedAt => ColumnType::DateTime.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)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.into(),
|
|
Self::Customer => Entity::belongs_to(super::customer::Entity)
|
|
.from(Column::CustomerId)
|
|
.to(super::customer::Column::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.into(),
|
|
Self::Lineitem => Entity::has_many(super::lineitem::Entity).into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Related<super::bakery::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Bakery.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::customer::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Customer.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::lineitem::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Lineitem.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|