diff --git a/sea-orm-macros/src/derives/attributes.rs b/sea-orm-macros/src/derives/attributes.rs index 9c0c24c4b..bf04c9771 100644 --- a/sea-orm-macros/src/derives/attributes.rs +++ b/sea-orm-macros/src/derives/attributes.rs @@ -7,6 +7,7 @@ pub mod derive_attr { pub column: Option, pub entity: Option, pub model: Option, + pub active_model: Option, pub primary_key: Option, pub relation: Option, pub schema_name: Option, diff --git a/sea-orm-macros/src/derives/entity.rs b/sea-orm-macros/src/derives/entity.rs index 5f9a0733c..b2e1fd66d 100644 --- a/sea-orm-macros/src/derives/entity.rs +++ b/sea-orm-macros/src/derives/entity.rs @@ -9,6 +9,7 @@ struct DeriveEntity { column_ident: syn::Ident, ident: syn::Ident, model_ident: syn::Ident, + active_model_ident: syn::Ident, primary_key_ident: syn::Ident, relation_ident: syn::Ident, schema_name: Option, @@ -22,6 +23,9 @@ impl DeriveEntity { let ident = input.ident; let column_ident = sea_attr.column.unwrap_or_else(|| format_ident!("Column")); let model_ident = sea_attr.model.unwrap_or_else(|| format_ident!("Model")); + let active_model_ident = sea_attr + .active_model + .unwrap_or_else(|| format_ident!("ActiveModel")); let primary_key_ident = sea_attr .primary_key .unwrap_or_else(|| format_ident!("PrimaryKey")); @@ -36,6 +40,7 @@ impl DeriveEntity { column_ident, ident, model_ident, + active_model_ident, primary_key_ident, relation_ident, schema_name, @@ -87,6 +92,7 @@ impl DeriveEntity { let Self { ident, model_ident, + active_model_ident, column_ident, primary_key_ident, relation_ident, @@ -98,6 +104,8 @@ impl DeriveEntity { impl sea_orm::entity::EntityTrait for #ident { type Model = #model_ident; + type ActiveModel = #active_model_ident; + type Column = #column_ident; type PrimaryKey = #primary_key_ident; diff --git a/src/entity/base_entity.rs b/src/entity/base_entity.rs index 6cd8b1052..5ed5d7572 100644 --- a/src/entity/base_entity.rs +++ b/src/entity/base_entity.rs @@ -1,7 +1,7 @@ use crate::{ - ActiveModelTrait, ColumnTrait, Delete, DeleteMany, DeleteOne, FromQueryResult, Insert, - ModelTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, Related, RelationBuilder, - RelationTrait, RelationType, Select, Update, UpdateMany, UpdateOne, + ActiveModelBehavior, ActiveModelTrait, ColumnTrait, Delete, DeleteMany, DeleteOne, + FromQueryResult, Insert, ModelTrait, PrimaryKeyToColumn, PrimaryKeyTrait, QueryFilter, Related, + RelationBuilder, RelationTrait, RelationType, Select, Update, UpdateMany, UpdateOne, }; use sea_query::{Alias, Iden, IntoIden, IntoTableRef, IntoValueTuple, TableRef}; use std::fmt::Debug; @@ -58,6 +58,9 @@ pub trait EntityTrait: EntityName { #[allow(missing_docs)] type Model: ModelTrait + FromQueryResult; + #[allow(missing_docs)] + type ActiveModel: ActiveModelBehavior; + #[allow(missing_docs)] type Column: ColumnTrait;