ModelQuery.union(): fix missing subquery variables
This commit is contained in:
parent
17685a44be
commit
e86356ae74
@ -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 <alice@gaudon.pro>",
|
||||
|
@ -219,6 +219,7 @@ export default class ModelQuery<M extends Model> implements WhereFieldConsumer<M
|
||||
.forEach(v => 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;
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,10 @@ describe('Test ModelQuery', () => {
|
||||
test('union queries', () => {
|
||||
const query = ModelQuery.select({table: 'model'} as unknown as ModelFactory<Model>, '*');
|
||||
const query2 = ModelQuery.select({table: 'model2'} as unknown as ModelFactory<Model>, '*');
|
||||
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'])
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user