Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeriveIntoActiveModel doesn't work with Enums #1972

Open
Stefan2409 opened this issue Nov 17, 2023 · 0 comments
Open

DeriveIntoActiveModel doesn't work with Enums #1972

Stefan2409 opened this issue Nov 17, 2023 · 0 comments

Comments

@Stefan2409
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant