73 lines
1.7 KiB
Rust
73 lines
1.7 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 {
|
|
"cakes_bakers"
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
|
pub struct Model {
|
|
pub cake_id: i32,
|
|
pub baker_id: i32,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
CakeId,
|
|
BakerId,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
|
pub enum PrimaryKey {
|
|
CakeId,
|
|
BakerId,
|
|
}
|
|
|
|
impl PrimaryKeyTrait for PrimaryKey {
|
|
fn auto_increment() -> bool {
|
|
false
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
pub enum Relation {
|
|
Cake,
|
|
Baker,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::CakeId => ColumnType::Integer.def(),
|
|
Self::BakerId => ColumnType::Integer.def(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
match self {
|
|
Self::Cake => Entity::belongs_to(super::cake::Entity)
|
|
.from(Column::CakeId)
|
|
.to(super::cake::Column::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.into(),
|
|
Self::Baker => Entity::belongs_to(super::baker::Entity)
|
|
.from(Column::BakerId)
|
|
.to(super::baker::Column::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|