diff --git a/src/query/update.rs b/src/query/update.rs index b5d404a05..8d5de7476 100644 --- a/src/query/update.rs +++ b/src/query/update.rs @@ -189,7 +189,8 @@ where for col in E::Column::iter() { let av = model.get(col); if av.is_set() { - self.query.value(col, av.unwrap()); + let expr = cast_text_as_enum(Expr::val(av.into_value().unwrap()), &col); + self.query.value(col, expr); } } self @@ -207,7 +208,7 @@ where #[cfg(test)] mod tests { - use crate::tests_cfg::{cake, fruit}; + use crate::tests_cfg::{cake, fruit, lunch_set, sea_orm_active_enums::Tea}; use crate::{entity::*, query::*, DbBackend}; use sea_query::{Expr, Value}; @@ -294,4 +295,33 @@ mod tests { r#"UPDATE "fruit" SET "id" = 3 WHERE "fruit"."id" = 2"#, ); } + + #[test] + fn update_7() { + assert_eq!( + Update::many(lunch_set::Entity) + .set(lunch_set::ActiveModel { + tea: Set(Tea::EverydayTea), + ..Default::default() + }) + .filter(lunch_set::Column::Tea.eq(Tea::BreakfastTea)) + .build(DbBackend::Postgres) + .to_string(), + r#"UPDATE "lunch_set" SET "tea" = CAST('EverydayTea' AS tea) WHERE "lunch_set"."tea" = CAST('BreakfastTea' AS tea)"#, + ); + } + + #[test] + fn update_8() { + assert_eq!( + Update::one(lunch_set::ActiveModel { + id: Unchanged(1), + tea: Set(Tea::EverydayTea), + ..Default::default() + }) + .build(DbBackend::Postgres) + .to_string(), + r#"UPDATE "lunch_set" SET "tea" = CAST('EverydayTea' AS tea) WHERE "lunch_set"."id" = 1"#, + ); + } }