From f39097c0e991e7726960c6aa3bab6a81efe2669f Mon Sep 17 00:00:00 2001 From: Bob den Os <108393871+BobdenOs@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:13:34 +0100 Subject: [PATCH] fix: Fix expand aliasing (#959) fixes: https://github.com/cap-js/cds-dbs/issues/948 --- hana/lib/HANAService.js | 2 +- test/scenarios/bookshop/read.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index baf2bf440..d9c57a949 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -446,7 +446,7 @@ class HANAService extends SQLService { ? [ { func: 'concat', - args: [{ ref: ['_parent_path_'] }, { val: `].${q.element.name}[`, param: false }], + args: [{ ref: ['_parent_path_'] }, { val: `].${alias}[`, param: false }], }, { func: 'lpad', args: [{ ref: ['$$RN$$'] }, { val: 6, param: false }, { val: '0', param: false }] }, ] diff --git a/test/scenarios/bookshop/read.test.js b/test/scenarios/bookshop/read.test.js index bc654fbf3..9e4eeb0a2 100644 --- a/test/scenarios/bookshop/read.test.js +++ b/test/scenarios/bookshop/read.test.js @@ -228,6 +228,16 @@ describe('Bookshop - Read', () => { expect(res.data.author.books.length).to.be.eq(2) }) + test('Expand Book with alias', async () => { + const { Books } = cds.entities('sap.capire.bookshop') + const res = await SELECT.one`ID as i, title as t, author as a { name as n, books as b { title as t } }`.from`${Books}[ID=252]` + + expect(res.i).to.be.eq(252) + expect(res.t).to.be.eq('Eleonora') + expect(res.a.n).to.be.eq('Edgar Allen Poe') + expect(res.a.b.length).to.be.eq(2) + }) + test.skip('Expand Book($count,$top,$orderby)', async () => { // REVISIT: requires changes in @sap/cds to allow $count inside expands const res = await GET(