Try more DeriveEntityModel

This commit is contained in:
Chris Tsang 2021-09-07 23:00:16 +08:00
parent a186338ff5
commit fa02a45fbf
2 changed files with 3 additions and 42 deletions

View File

@ -2,14 +2,9 @@ use crate as sea_orm;
use crate::entity::prelude::*; use crate::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
#[sea_orm(table_name = "filling")]
pub struct Entity; pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"filling"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model { pub struct Model {
pub id: i32, pub id: i32,

View File

@ -1,37 +1,15 @@
use crate as sea_orm; use crate as sea_orm;
use crate::entity::prelude::*; use crate::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel, DeriveModel, DeriveActiveModel)]
#[sea_orm(table_name = "fruit")] #[sea_orm(table_name = "fruit")]
pub struct Entity;
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model { pub struct Model {
#[sea_orm(primary_key)]
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub cake_id: Option<i32>, pub cake_id: Option<i32>,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Name,
CakeId,
}
#[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, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation { pub enum Relation {
#[sea_orm( #[sea_orm(
@ -42,18 +20,6 @@ pub enum Relation {
Cake, Cake,
} }
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::String(None).def(),
Self::CakeId => ColumnType::Integer.def(),
}
}
}
impl Related<super::cake::Entity> for Entity { impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef { fn to() -> RelationDef {
Relation::Cake.def() Relation::Cake.def()