Skip to content

Commit

Permalink
Fix a bug where incorrect sibling count was passed down for connectiv…
Browse files Browse the repository at this point in the history
…e used a value resulting in missing parens in generated query
  • Loading branch information
vampirical committed Mar 16, 2024
1 parent b8cb348 commit 687bf9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wheres.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function getWhereSql(
Array.prototype.push.apply(values, currentPack.values);
}

const connectiveQuery = joinWithConnective(connectiveQueryParts, value.connective, siblings);
const connectiveQuery = joinWithConnective(connectiveQueryParts, value.connective, fields.length - 1);
queryParts.push(connectiveQuery);

continue;
Expand Down
11 changes: 11 additions & 0 deletions tests/RecordQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,17 @@ test('nested array and', async (t) => {
t.is(results.length, 5);
});

test('connective used as value wrap itself in parens', async (t) => {
const q = await new SQL.RecordQuery(pool, QueryTestRecord)
.where({aFlag: SQL.or(true, null), displayName: SQL.like('Display Name 10,%')})
.run();

for (const row of q) {
t.true(row.aFlag === true || row.aFlag === null);
t.regex(row.displayName, /Display Name 10,.*/);
}
});

test('connectives as values support nested connectives', async (t) => {
const q = await new SQL.RecordQuery(pool, QueryTestRecord)
.where({
Expand Down

0 comments on commit 687bf9d

Please sign in to comment.