diff --git a/src/query/condition.rs b/src/query/condition.rs index 6539181ff..58b528819 100644 --- a/src/query/condition.rs +++ b/src/query/condition.rs @@ -46,6 +46,24 @@ impl Condition { /// /// If it's an [`Condition::any`], it will be separated from the others by an `" OR "` in the query. If it's /// an [`Condition::all`], it will be separated by an `" AND "`. + /// + /// ``` + /// use sea_query::{*, tests_cfg::*}; + /// + /// let statement = sea_query::Query::select() + /// .column(Glyph::Id) + /// .from(Glyph::Table) + /// .cond_where( + /// Cond::all() + /// .add(Expr::col(Glyph::Aspect).eq(0).into_condition().not()) + /// .add(Expr::col(Glyph::Id).eq(0).into_condition().not()), + /// ) + /// .to_string(PostgresQueryBuilder); + /// assert_eq!( + /// statement, + /// r#"SELECT "id" FROM "glyph" WHERE (NOT ("aspect" = 0)) AND (NOT ("id" = 0))"# + /// ); + /// ``` #[allow(clippy::should_implement_trait)] pub fn add<C>(mut self, condition: C) -> Self where @@ -58,7 +76,7 @@ impl Condition { return self; } // Skip the junction if there is only one. - if c.conditions.len() == 1 { + if c.conditions.len() == 1 && !c.negate { expr = c.conditions.pop().unwrap(); } }