-
I use sea-orm-cli to generate entities, but I don't see Entity in the file. pub use super::animal::Entity as Animal; //! SeaORM Entity. Generated by sea-orm-codegen 0.6.0
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "animal")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}
impl ActiveModelBehavior for ActiveModel {} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @Ilqjx, welcome! Good questions! The #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn schema_name(&self) -> Option<&str> {
None
}
fn table_name(&self) -> &str {
"cake"
}
} Adapted from https://www.sea-ql.org/SeaORM/docs/generate-entity/expanded-entity-structure#entity The source code of sea-orm/sea-orm-macros/src/derives/entity_model.rs Lines 45 to 59 in 56cf4ea |
Beta Was this translation helpful? Give feedback.
-
@billy1624 Thanks for your reply |
Beta Was this translation helpful? Give feedback.
Hey @Ilqjx, welcome! Good questions!
The
DeriveEntityModel
proc_macro actually definedEntity
struct and implementedEntityName
trait for you under the hood.Adapted from https://www.sea-ql.org/SeaORM/docs/generate-entity/expanded-entity-structure#entity
The source code of
DeriveEntityModel
proc_macro:sea-orm/sea-orm-macros/src/derives/entity_model.rs
Lines 45 to 59 in 56cf4ea