This commit is contained in:
Chris Tsang 2021-10-02 00:02:17 +08:00
parent a0be9239bd
commit 7c82670d12
2 changed files with 54 additions and 0 deletions

View File

@ -774,4 +774,32 @@ mod tests {
assert_eq!(hello::Column::Two.to_string().as_str(), "two");
assert_eq!(hello::Column::Three3.to_string().as_str(), "THREE");
}
#[test]
#[cfg(feature = "macros")]
fn column_name_enum_name_3() {
use sea_query::Iden;
mod my_entity {
use crate as sea_orm;
use crate::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "my_entity")]
pub struct Model {
#[sea_orm(primary_key, enum_name = "IdentityColumn", column_name = "id")]
pub id: i32,
#[sea_orm(column_name = "type")]
pub type_: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
assert_eq!(my_entity::Column::IdentityColumn.to_string().as_str(), "id");
assert_eq!(my_entity::Column::Type.to_string().as_str(), "type");
}
}

View File

@ -314,6 +314,32 @@ pub trait QueryFilter: Sized {
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
/// );
/// ```
///
/// A slightly more complex example.
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::Expr, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
/// .filter(
/// Condition::all()
/// .add(
/// Condition::all()
/// .not()
/// .add(Expr::val(1).eq(1))
/// .add(Expr::val(2).eq(2))
/// )
/// .add(
/// Condition::any()
/// .add(Expr::val(3).eq(3))
/// .add(Expr::val(4).eq(4))
/// )
/// )
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE (NOT (1 = 1 AND 2 = 2)) AND (3 = 3 OR 4 = 4)"#
/// );
/// ```
fn filter<F>(mut self, filter: F) -> Self
where
F: IntoCondition,