From e86356ae7427da5baf7fcd8ab89553c80d7010c2 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 6 Sep 2020 16:02:53 +0200 Subject: [PATCH] ModelQuery.union(): fix missing subquery variables --- package.json | 2 +- src/db/ModelQuery.ts | 1 + test/ModelQuery.test.ts | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2a8e0f6..b96167d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wms-core", - "version": "0.22.0-rc.6", + "version": "0.22.0-rc.7", "description": "Node web application framework and toolbelt.", "repository": "https://gitlab.com/ArisuOngaku/wms-core", "author": "Alice Gaudon ", diff --git a/src/db/ModelQuery.ts b/src/db/ModelQuery.ts index 277acb0..f83f3cd 100644 --- a/src/db/ModelQuery.ts +++ b/src/db/ModelQuery.ts @@ -219,6 +219,7 @@ export default class ModelQuery implements WhereFieldConsumer variables.push(v)); this._where.flatMap(v => this.getVariables(v)) .forEach(v => variables.push(v)); + this._union?.query.variables.forEach(v => variables.push(v)); return variables; } diff --git a/test/ModelQuery.test.ts b/test/ModelQuery.test.ts index 3cdd3d8..08d3c15 100644 --- a/test/ModelQuery.test.ts +++ b/test/ModelQuery.test.ts @@ -69,8 +69,10 @@ describe('Test ModelQuery', () => { test('union queries', () => { const query = ModelQuery.select({table: 'model'} as unknown as ModelFactory, '*'); const query2 = ModelQuery.select({table: 'model2'} as unknown as ModelFactory, '*'); + query2.where('f2', 'v2'); query.union(query2, 'model.f1', 'DESC', false, 8); - expect(query.toString(true)).toBe("(SELECT `model`.* FROM `model`) UNION (SELECT `model2`.* FROM `model2`) ORDER BY `model`.`f1` DESC LIMIT 8"); + expect(query.toString(true)).toBe("(SELECT `model`.* FROM `model`) UNION (SELECT `model2`.* FROM `model2` WHERE `f2`=?) ORDER BY `model`.`f1` DESC LIMIT 8"); + expect(query.variables).toStrictEqual(['v2']) }); });