Skip to content

Commit

Permalink
Merge pull request #2186 from SeaQL/entity-behavior
Browse files Browse the repository at this point in the history
Associate `ActiveModel` to `EntityTrait`
  • Loading branch information
tyt2y3 committed May 9, 2024
2 parents c2b8c44 + 3b3a446 commit e77cc5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/attributes.rs
Expand Up @@ -7,6 +7,7 @@ pub mod derive_attr {
pub column: Option<syn::Ident>,
pub entity: Option<syn::Ident>,
pub model: Option<syn::Ident>,
pub active_model: Option<syn::Ident>,
pub primary_key: Option<syn::Ident>,
pub relation: Option<syn::Ident>,
pub schema_name: Option<syn::Lit>,
Expand Down
8 changes: 8 additions & 0 deletions sea-orm-macros/src/derives/entity.rs
Expand Up @@ -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<syn::Lit>,
Expand All @@ -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"));
Expand All @@ -36,6 +40,7 @@ impl DeriveEntity {
column_ident,
ident,
model_ident,
active_model_ident,
primary_key_ident,
relation_ident,
schema_name,
Expand Down Expand Up @@ -87,6 +92,7 @@ impl DeriveEntity {
let Self {
ident,
model_ident,
active_model_ident,
column_ident,
primary_key_ident,
relation_ident,
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions 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;
Expand Down Expand Up @@ -58,6 +58,9 @@ pub trait EntityTrait: EntityName {
#[allow(missing_docs)]
type Model: ModelTrait<Entity = Self> + FromQueryResult;

#[allow(missing_docs)]
type ActiveModel: ActiveModelBehavior<Entity = Self>;

#[allow(missing_docs)]
type Column: ColumnTrait;

Expand Down

0 comments on commit e77cc5f

Please sign in to comment.