sea-orm
sea-orm copied to clipboard
DeriveIntoActiveModel doesn't work with Enums
I have created the following entity model:
use super::sea_orm_active_enums::*;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
#[sea_orm(unique)]
pub email: String,
#[sea_orm(column_type = "Text")]
pub password: String,
pub role: Role,
pub first_name: String,
pub last_name: String,
pub date_of_birth: Date,
pub image_url: Option<String>,
pub created_at: Option<DateTime>,
pub updated_at: Option<DateTime>,
pub created_from: Option<i64>,
pub updated_from: Option<i64>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
#[derive(Deserialize, Debug, Validate, DeriveIntoActiveModel)]
pub struct UpdateUser {
#[validate(email)]
email: String,
#[validate(length(max = 50))]
first_name: String,
#[validate(length(max = 50))]
last_name: String,
date_of_birth: Date,
role: Role,
}
with the following enum definition for Role:
use sea_orm::{entity::prelude::*};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "role")]
pub enum Role {
#[sea_orm(string_value = "Admin")]
Admin,
#[sea_orm(string_value = "User")]
User,
}
The Problem is that I'm getting the error: the trait bound sea_orm_active_enums::Role: IntoActiveValue<_>
is not satisfied with my UpdateUser struct.
The trait bound should be satisfied already. If I write a User with the whole Model to the DB everything works fine. So there's something missing in the DeriveIntoActiveModel implementation with enums.
I'm using sea-orm 12.6.