diff --git a/src/entity/column.rs b/src/entity/column.rs index 2117182be..de987e11b 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -61,7 +61,8 @@ macro_rules! bind_vec_func { V: Into, I: IntoIterator, { - Expr::col((self.entity_name(), *self)).$func(v) + let v_with_enum_cast = v.into_iter().map(|v| self.save_as(Expr::val(v))); + Expr::col((self.entity_name(), *self)).$func(v_with_enum_cast) } }; } diff --git a/tests/active_enum_tests.rs b/tests/active_enum_tests.rs index 547532052..27babd6c0 100644 --- a/tests/active_enum_tests.rs +++ b/tests/active_enum_tests.rs @@ -8,7 +8,7 @@ use sea_orm::{ entity::prelude::*, entity::*, sea_query::{BinOper, Expr}, - ActiveEnum as ActiveEnumTrait, DatabaseConnection, + ActiveEnum as ActiveEnumTrait, DatabaseConnection, QueryTrait, }; #[sea_orm_macros::test] @@ -98,6 +98,7 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> { .await? .unwrap() ); + assert_eq!( model, Entity::find() @@ -109,6 +110,24 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> { .await? .unwrap() ); + // Equivalent to the above. + let select_with_tea_in = Entity::find().filter(Column::Tea.is_in([Tea::EverydayTea])); + assert_eq!( + select_with_tea_in + .build(sea_orm::DatabaseBackend::Postgres) + .to_string(), + [ + "SELECT \"active_enum\".\"id\",", + "\"active_enum\".\"category\",", + "\"active_enum\".\"color\",", + "CAST(\"active_enum\".\"tea\" AS text)", + "FROM \"active_enum\"", + "WHERE \"active_enum\".\"tea\" IN (CAST('EverydayTea' AS tea))", + ] + .join(" ") + ); + assert_eq!(model, select_with_tea_in.one(db).await?.unwrap()); + assert_eq!( model, Entity::find() @@ -121,6 +140,26 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> { .await? .unwrap() ); + // Equivalent to the above. + let select_with_tea_not_in = Entity::find() + .filter(Column::Tea.is_not_null()) + .filter(Column::Tea.is_not_in([Tea::BreakfastTea])); + assert_eq!( + select_with_tea_not_in + .build(sea_orm::DatabaseBackend::Postgres) + .to_string(), + [ + "SELECT \"active_enum\".\"id\",", + "\"active_enum\".\"category\",", + "\"active_enum\".\"color\",", + "CAST(\"active_enum\".\"tea\" AS text)", + "FROM \"active_enum\"", + "WHERE \"active_enum\".\"tea\" IS NOT NULL", + "AND \"active_enum\".\"tea\" NOT IN (CAST('BreakfastTea' AS tea))", + ] + .join(" ") + ); + assert_eq!(model, select_with_tea_not_in.one(db).await?.unwrap()); let res = model.delete(db).await?; diff --git a/tests/enum_primary_key_tests.rs b/tests/enum_primary_key_tests.rs index ce487bbc0..8364865d4 100644 --- a/tests/enum_primary_key_tests.rs +++ b/tests/enum_primary_key_tests.rs @@ -113,6 +113,15 @@ pub async fn insert_teas(db: &DatabaseConnection) -> Result<(), DbErr> { .await? .unwrap() ); + // Equivalent to the above. + assert_eq!( + model, + Entity::find() + .filter(Column::Id.is_in([Tea::EverydayTea])) + .one(db) + .await? + .unwrap() + ); let res = model.delete(db).await?;