diff --git a/lib/query/querybuilder.js b/lib/query/querybuilder.js index 4b923879be..60c224b9f8 100644 --- a/lib/query/querybuilder.js +++ b/lib/query/querybuilder.js @@ -1233,7 +1233,11 @@ class Builder extends EventEmitter { // Set a lock for update constraint. forUpdate(...tables) { this._single.lock = lockMode.forUpdate; - this._single.lockTables = tables; + if (tables.length === 1 && Array.isArray(tables[0])) { + this._single.lockTables = tables[0]; + } else { + this._single.lockTables = tables; + } return this; } diff --git a/test/unit/query/builder.js b/test/unit/query/builder.js index c46f9d4cb8..c11047df24 100644 --- a/test/unit/query/builder.js +++ b/test/unit/query/builder.js @@ -6717,6 +6717,34 @@ describe('QueryBuilder', () => { ); }); + it('lock only some tables for update (with array #4878)', () => { + testsql( + qb() + .select('*') + .from('foo') + .where('bar', '=', 'baz') + .forUpdate(['lo', 'rem']), + { + mysql: { + sql: 'select * from `foo` where `bar` = ? for update', + bindings: ['baz'], + }, + pg: { + sql: 'select * from "foo" where "bar" = ? for update of "lo", "rem"', + bindings: ['baz'], + }, + mssql: { + sql: 'select * from [foo] with (UPDLOCK) where [bar] = ?', + bindings: ['baz'], + }, + oracledb: { + sql: 'select * from "foo" where "bar" = ? for update', + bindings: ['baz'], + }, + } + ); + }); + it('lock for update with skip locked #1937', () => { testsql(qb().select('*').from('foo').first().forUpdate().skipLocked(), { mysql: {