Add cake_expanded entity file for docs demo
This commit is contained in:
parent
a280a227d8
commit
a45c44cfc5
94
src/tests_cfg/cake_expanded.rs
Normal file
94
src/tests_cfg/cake_expanded.rs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
use crate as sea_orm;
|
||||||
|
use crate::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||||
|
pub struct Entity;
|
||||||
|
|
||||||
|
impl EntityName for Entity {
|
||||||
|
fn table_name(&self) -> &str {
|
||||||
|
"cake"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
|
pub struct Model {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
pub enum Column {
|
||||||
|
Id,
|
||||||
|
Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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 {
|
||||||
|
Fruit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ColumnTrait for Column {
|
||||||
|
type EntityName = Entity;
|
||||||
|
|
||||||
|
fn def(&self) -> ColumnDef {
|
||||||
|
match self {
|
||||||
|
Self::Id => ColumnType::Integer.def(),
|
||||||
|
Self::Name => ColumnType::String(None).def(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct CakeToFilling;
|
||||||
|
|
||||||
|
impl Linked for CakeToFilling {
|
||||||
|
type FromEntity = Entity;
|
||||||
|
|
||||||
|
type ToEntity = super::filling::Entity;
|
||||||
|
|
||||||
|
fn link(&self) -> Vec<RelationDef> {
|
||||||
|
vec![
|
||||||
|
super::cake_filling::Relation::Cake.def().rev(),
|
||||||
|
super::cake_filling::Relation::Filling.def(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
@ -18,6 +18,12 @@ pub enum Relation {
|
|||||||
to = "super::cake::Column::Id"
|
to = "super::cake::Column::Id"
|
||||||
)]
|
)]
|
||||||
Cake,
|
Cake,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::cake_expanded::Entity",
|
||||||
|
from = "Column::CakeId",
|
||||||
|
to = "super::cake_expanded::Column::Id"
|
||||||
|
)]
|
||||||
|
CakeExpanded,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Related<super::cake::Entity> for Entity {
|
impl Related<super::cake::Entity> for Entity {
|
||||||
@ -26,4 +32,10 @@ impl Related<super::cake::Entity> for Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Related<super::cake_expanded::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::CakeExpanded.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
//! Configurations for test cases and examples. Not intended for actual use.
|
//! Configurations for test cases and examples. Not intended for actual use.
|
||||||
|
|
||||||
pub mod cake;
|
pub mod cake;
|
||||||
|
pub mod cake_expanded;
|
||||||
pub mod cake_filling;
|
pub mod cake_filling;
|
||||||
pub mod cake_filling_price;
|
pub mod cake_filling_price;
|
||||||
pub mod filling;
|
pub mod filling;
|
||||||
pub mod fruit;
|
pub mod fruit;
|
||||||
|
|
||||||
pub use cake::Entity as Cake;
|
pub use cake::Entity as Cake;
|
||||||
|
pub use cake_expanded::Entity as CakeExpanded;
|
||||||
pub use cake_filling::Entity as CakeFilling;
|
pub use cake_filling::Entity as CakeFilling;
|
||||||
pub use cake_filling_price::Entity as CakeFillingPrice;
|
pub use cake_filling_price::Entity as CakeFillingPrice;
|
||||||
pub use filling::Entity as Filling;
|
pub use filling::Entity as Filling;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user