Merge pull request #2186 from SeaQL/entity-behavior
Associate `ActiveModel` to `EntityTrait`
This commit is contained in:
commit
e77cc5fa65
@ -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>,
|
||||
|
@ -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>,
|
||||
@ -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;
|
||||
|
@ -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<Entity = Self> + FromQueryResult;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
type ActiveModel: ActiveModelBehavior<Entity = Self>;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
type Column: ColumnTrait;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user