diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index 0603662c..e63cbea4 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -641,6 +641,30 @@ where fn into_active_value(self) -> ActiveValue; } +impl IntoActiveValue> for Option +where + V: IntoActiveValue + Into + Nullable, +{ + fn into_active_value(self) -> ActiveValue> { + match self { + Some(value) => Set(Some(value)), + None => NotSet, + } + } +} + +impl IntoActiveValue> for Option> +where + V: IntoActiveValue + Into + Nullable, +{ + fn into_active_value(self) -> ActiveValue> { + match self { + Some(value) => Set(value), + None => NotSet, + } + } +} + macro_rules! impl_into_active_value { ($ty: ty) => { impl IntoActiveValue<$ty> for $ty { @@ -648,24 +672,6 @@ macro_rules! impl_into_active_value { Set(self) } } - - impl IntoActiveValue> for Option<$ty> { - fn into_active_value(self) -> ActiveValue> { - match self { - Some(value) => Set(Some(value)), - None => NotSet, - } - } - } - - impl IntoActiveValue> for Option> { - fn into_active_value(self) -> ActiveValue> { - match self { - Some(value) => Set(value), - None => NotSet, - } - } - } }; } diff --git a/tests/common/features/custom_active_model.rs b/tests/common/features/custom_active_model.rs new file mode 100644 index 00000000..6b6e6977 --- /dev/null +++ b/tests/common/features/custom_active_model.rs @@ -0,0 +1,40 @@ +use super::sea_orm_active_enums::*; +use sea_orm::entity::prelude::*; +use sea_orm::{ActiveValue, IntoActiveValue}; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[cfg_attr(feature = "sqlx-postgres", sea_orm(schema_name = "public"))] +#[sea_orm(table_name = "custom_active_model")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub weight: Option, + pub amount: Option, + pub category: Option, + pub color: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} + +#[derive(Clone, Debug, PartialEq, DeriveIntoActiveModel)] +pub struct CustomActiveModel { + pub weight: Option, + pub amount: Option>, + pub category: Option, + pub color: Option>, +} + +impl IntoActiveValue for Category { + fn into_active_value(self) -> ActiveValue { + ActiveValue::set(self) + } +} + +impl IntoActiveValue for Color { + fn into_active_value(self) -> ActiveValue { + ActiveValue::set(self) + } +} diff --git a/tests/common/features/mod.rs b/tests/common/features/mod.rs index 0b26b261..ce95af17 100644 --- a/tests/common/features/mod.rs +++ b/tests/common/features/mod.rs @@ -2,6 +2,7 @@ pub mod active_enum; pub mod active_enum_child; pub mod applog; pub mod byte_primary_key; +pub mod custom_active_model; pub mod insert_default; pub mod json_struct; pub mod json_vec;