sea-orm/examples/basic/src/example_cake.rs
Billy Chan 4f8ad56cc4
Cont. Added support for using sea-orm with #[deny(missing_docs)] (#1531)
* Added support for using sea-orm with #[deny(missing_docs)] (#1522)

* feat(macros): Added documentation tags for generated entities

* chore: Added deny(missing_docs) attribute to basic example

* chore: Fix clippy errors

* ci: test missing docs of derive macros generated types

* Try missing docs (CI should fail)

* Revert "Try missing docs (CI should fail)"

This reverts commit 83356bfca8939e7807f14bad8bb816fcabc1bf7b.

---------

Co-authored-by: Lewin Probst, M.Sc <30552361+emirror-de@users.noreply.github.com>
2023-03-10 21:49:08 +08:00

56 lines
1.1 KiB
Rust

//! 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<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
impl Related<super::filling::Entity> for Entity {
fn to() -> RelationDef {
super::cake_filling::Relation::Filling.def()
}
fn via() -> Option<RelationDef> {
Some(super::cake_filling::Relation::Cake.def().rev())
}
}
#[async_trait::async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(self, _db: &C, _insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
Ok(self)
}
}