//! The `cake` entity. use sea_orm::entity::prelude::*; /// Cake entity #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "cake")] pub struct Model { #[sea_orm(primary_key)] /// id field pub id: i32, /// name field pub name: String, } /// Cake relation #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { /// Fruit relation Fruit, } impl RelationTrait for Relation { fn def(&self) -> RelationDef { match self { Self::Fruit => Entity::has_many(super::fruit::Entity).into(), } } } impl Related for Entity { fn to() -> RelationDef { Relation::Fruit.def() } } impl Related for Entity { fn to() -> RelationDef { super::cake_filling::Relation::Filling.def() } fn via() -> Option { Some(super::cake_filling::Relation::Cake.def().rev()) } } #[async_trait::async_trait] impl ActiveModelBehavior for ActiveModel { async fn before_save(self, _db: &C, _insert: bool) -> Result where C: ConnectionTrait, { Ok(self) } }