From d28a1ff15840c9c9b000863bcee628e3de21e0fb Mon Sep 17 00:00:00 2001 From: D050513 Date: Mon, 4 Nov 2024 11:29:38 +0100 Subject: [PATCH 1/4] fix: rewrite to path expression, if alias for relative is already used in subselect to avoid sql error --- lib/utils.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 207dfd2..269cab6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -121,7 +121,17 @@ const _buildSubSelect = (model, { entity, relative, element, next }, row, previo const targetAlias = _alias(element._target) const relativeAlias = _alias(relative) - childCqn.where(relative._relations[element.name].join(targetAlias, relativeAlias)) + let w = relative._relations[element.name].join(targetAlias, relativeAlias) + + // REVISIT: rewrite to path expression, if alias for relative is already used in subselect to avoid sql error + if (previousCqn?._aliases.has(relativeAlias)) { + let t + for (const a in entity.associations) if (entity.associations[a].target === relative.name) t = entity.associations[a] + if (t && w[0]?.xpr) for (const ele of w[0].xpr) if (ele.ref?.[0] === relativeAlias) ele.ref.splice(0, 1, as, t.name) + } + childCqn._aliases = new Set(previousCqn ? [...previousCqn._aliases.values(), as] : [as]) + + childCqn.where(w) if (previousCqn) childCqn.where('exists', previousCqn) else childCqn.where(_addKeysToWhere(keys, row, as)) From 31bc0af795429de27fa60f5e1d46134a8dc89ea3 Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 27 Nov 2024 10:26:25 +0100 Subject: [PATCH 2/4] wait(11) --- test/personal-data/crud.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/personal-data/crud.test.js b/test/personal-data/crud.test.js index a72475e..6357aaf 100644 --- a/test/personal-data/crud.test.js +++ b/test/personal-data/crud.test.js @@ -4,10 +4,10 @@ const { POST: _POST, PATCH: _PATCH, GET: _GET, DELETE: _DELETE, data } = cds.tes // the persistent outbox adds a delay const wait = require('util').promisify(setTimeout) -const POST = (...args) => _POST(...args).then(async res => (await wait(7), res)) -const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(7), res)) -const GET = (...args) => _GET(...args).then(async res => (await wait(7), res)) -const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(7), res)) +const POST = (...args) => _POST(...args).then(async res => (await wait(11), res)) +const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(11), res)) +const GET = (...args) => _GET(...args).then(async res => (await wait(11), res)) +const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(11), res)) // TODO: @cap-js/sqlite doesn't support structured properties // // needed for testing structured properties From 1b7d14f0c6bfac04418333b512b34f1781c808ab Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 27 Nov 2024 10:28:30 +0100 Subject: [PATCH 3/4] wait(42) --- test/personal-data/crud.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/personal-data/crud.test.js b/test/personal-data/crud.test.js index 6357aaf..ef691c8 100644 --- a/test/personal-data/crud.test.js +++ b/test/personal-data/crud.test.js @@ -4,10 +4,10 @@ const { POST: _POST, PATCH: _PATCH, GET: _GET, DELETE: _DELETE, data } = cds.tes // the persistent outbox adds a delay const wait = require('util').promisify(setTimeout) -const POST = (...args) => _POST(...args).then(async res => (await wait(11), res)) -const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(11), res)) -const GET = (...args) => _GET(...args).then(async res => (await wait(11), res)) -const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(11), res)) +const POST = (...args) => _POST(...args).then(async res => (await wait(42), res)) +const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(42), res)) +const GET = (...args) => _GET(...args).then(async res => (await wait(42), res)) +const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(42), res)) // TODO: @cap-js/sqlite doesn't support structured properties // // needed for testing structured properties From 51716fca218ecfd53f8e9d1d8579b824017918ab Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 27 Nov 2024 10:33:43 +0100 Subject: [PATCH 4/4] DELAY = process.env.CI ? 42 : 7 --- test/personal-data/crud.test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/personal-data/crud.test.js b/test/personal-data/crud.test.js index ef691c8..1ea12c0 100644 --- a/test/personal-data/crud.test.js +++ b/test/personal-data/crud.test.js @@ -4,10 +4,11 @@ const { POST: _POST, PATCH: _PATCH, GET: _GET, DELETE: _DELETE, data } = cds.tes // the persistent outbox adds a delay const wait = require('util').promisify(setTimeout) -const POST = (...args) => _POST(...args).then(async res => (await wait(42), res)) -const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(42), res)) -const GET = (...args) => _GET(...args).then(async res => (await wait(42), res)) -const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(42), res)) +const DELAY = process.env.CI ? 42 : 7 +const POST = (...args) => _POST(...args).then(async res => (await wait(DELAY), res)) +const PATCH = (...args) => _PATCH(...args).then(async res => (await wait(DELAY), res)) +const GET = (...args) => _GET(...args).then(async res => (await wait(DELAY), res)) +const DELETE = (...args) => _DELETE(...args).then(async res => (await wait(DELAY), res)) // TODO: @cap-js/sqlite doesn't support structured properties // // needed for testing structured properties