From 4995662b1955aae477c14a1c7877758e88927713 Mon Sep 17 00:00:00 2001 From: Bob den Os Date: Fri, 19 Apr 2024 11:54:55 +0200 Subject: [PATCH 1/3] Ignore associations that don't have foreign key references --- hana/lib/HANAService.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index 7f91dbb46..41fdbd812 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -453,6 +453,7 @@ class HANAService extends SQLService { let fkeys = x.element._foreignKeys if (typeof fkeys === 'function') fkeys = fkeys.call(x.element) fkeys.forEach(k => { + if (!k?.parentElement?.name) return // not all associations have foreign key references if (!parent.SELECT.columns.find(c => this.column_name(c) === k.parentElement.name)) { parent.SELECT.columns.push({ ref: [parent.as, k.parentElement.name] }) } From b1816e450e5aa0e78b1f01188116fa0c09350f2f Mon Sep 17 00:00:00 2001 From: Bob den Os Date: Wed, 24 Apr 2024 14:46:20 +0200 Subject: [PATCH 2/3] Add test that uses static association --- test/compliance/SELECT.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/compliance/SELECT.test.js b/test/compliance/SELECT.test.js index 1bd02bc75..1b4438ab5 100644 --- a/test/compliance/SELECT.test.js +++ b/test/compliance/SELECT.test.js @@ -204,6 +204,19 @@ describe('SELECT', () => { assert.strictEqual(Object.keys(res[0].author).length, 200) }) + test('expand association with static values', async () => { + const cqn = { + SELECT: { + from: { ref: ['complex.associations.unmanaged.Authors'] }, + columns: [{ ref: ['ID'] }, { ref: ['static'], expand: ['*'] }] + }, + } + + const res = await cds.run(cqn) + // ensure that all values are returned in json format + assert.strictEqual(res[0].static.length, 1) + }) + test.skip('invalid cast (wrong)', async () => { await expect( cds.run(CQL` From 7e65401ae739235dd04053a487f88961a95e58a0 Mon Sep 17 00:00:00 2001 From: Bob den Os Date: Wed, 24 Apr 2024 14:58:44 +0200 Subject: [PATCH 3/3] Add updates to test model and data --- test/compliance/resources/db/complex/associationsUnmanaged.cds | 1 + .../db/data/complex.associations.unmanaged.Authors.csv | 2 ++ .../resources/db/data/complex.associations.unmanaged.Books.csv | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 test/compliance/resources/db/data/complex.associations.unmanaged.Authors.csv create mode 100644 test/compliance/resources/db/data/complex.associations.unmanaged.Books.csv diff --git a/test/compliance/resources/db/complex/associationsUnmanaged.cds b/test/compliance/resources/db/complex/associationsUnmanaged.cds index 4919981c1..dde05cdd0 100644 --- a/test/compliance/resources/db/complex/associationsUnmanaged.cds +++ b/test/compliance/resources/db/complex/associationsUnmanaged.cds @@ -11,4 +11,5 @@ entity Authors { key ID : Integer; name : String(111); books : Association to many Books on books.author = $self; + static : Association to many Books on static.author = $self and static.ID > 0; } diff --git a/test/compliance/resources/db/data/complex.associations.unmanaged.Authors.csv b/test/compliance/resources/db/data/complex.associations.unmanaged.Authors.csv new file mode 100644 index 000000000..f68ab4983 --- /dev/null +++ b/test/compliance/resources/db/data/complex.associations.unmanaged.Authors.csv @@ -0,0 +1,2 @@ +ID;name +1;Emily diff --git a/test/compliance/resources/db/data/complex.associations.unmanaged.Books.csv b/test/compliance/resources/db/data/complex.associations.unmanaged.Books.csv new file mode 100644 index 000000000..4caf39e2e --- /dev/null +++ b/test/compliance/resources/db/data/complex.associations.unmanaged.Books.csv @@ -0,0 +1,2 @@ +ID;title;author_ID +1;Wuthering Heights;1