Skip to content

Commit

Permalink
fix bug in Condition::add where Condition negation is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoulaj authored and tyt2y3 committed Oct 26, 2021
1 parent 5b3a4e6 commit 3830737
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/query/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
Expand Down

0 comments on commit 3830737

Please sign in to comment.