Skip to content

Commit

Permalink
fix(core): fix auto-joining with $not operator
Browse files Browse the repository at this point in the history
Closes #1537
  • Loading branch information
B4nan committed Mar 15, 2021
1 parent 4e36df2 commit 8071fd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/knex/src/query/CriteriaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class CriteriaNode {

if (parentPath) {
ret = parentPath + '.' + ret;
} else if (this.parent?.entityName && ret) {
} else if (this.parent?.entityName && ret && this.prop) {
ret = this.parent.entityName + '.' + ret;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/QueryBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,20 @@ describe('QueryBuilder', () => {
'order by `e1`.`email` asc');
});

test('select with auto-joining and $not (GH issue #1537)', async () => {
const qb1 = orm.em.createQueryBuilder(Book2, 'a');
qb1.select('*').where({
$or: [
{ author: { name: 'test' } },
{ $not: { author: { name: 'wut' } } },
],
});
expect(qb1.getQuery()).toEqual('select `a`.*, `a`.price * 1.19 as `price_taxed` ' +
'from `book2` as `a` ' +
'left join `author2` as `e1` on `a`.`author_id` = `e1`.`id` ' +
'where (`e1`.`name` = ? or not (`e1`.`name` = ?))');
});

test('select by PK via operator', async () => {
const qb1 = orm.em.createQueryBuilder(Author2, 'a');
qb1.select('*').where({ $in: [1, 2] });
Expand Down

0 comments on commit 8071fd0

Please sign in to comment.