Skip to content

Commit

Permalink
fix: fix NOT operator sometimes producing incorrect queries (#17044)
Browse files Browse the repository at this point in the history
  • Loading branch information
WikiRik committed Feb 5, 2024
1 parent 68be977 commit 63ba367
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 0 additions & 4 deletions packages/core/src/dialects/abstract/where-sql-builder.ts
Expand Up @@ -879,10 +879,6 @@ function wrapWithNot(sql: string): string {
return '';
}

if (sql.startsWith('(') && sql.endsWith(')')) {
return `NOT ${sql}`;
}

return `NOT (${sql})`;
}

Expand Down
17 changes: 17 additions & 0 deletions packages/core/test/unit/sql/where.test.ts
Expand Up @@ -2696,6 +2696,23 @@ Caused by: "undefined" cannot be escaped`),
default: 'NOT ([intAttr1] = 1 AND [intAttr2] = 2)',
});

testSql({
[Op.not]: {
[Op.or]: {
[Op.and]: {
intAttr1: 1,
intAttr2: 2,
},
[Op.or]: {
intAttr1: 1,
intAttr2: 2,
},
},
},
}, {
default: 'NOT (([intAttr1] = 1 AND [intAttr2] = 2) OR ([intAttr1] = 1 OR [intAttr2] = 2))',
});

// Op.not, Op.and, Op.or can reside on the same object as attributes
testSql({
intAttr1: 1,
Expand Down

0 comments on commit 63ba367

Please sign in to comment.