Skip to content

Commit

Permalink
fix: Support static conditions inside unmanaged associations (#682)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Vogel <[email protected]>
  • Loading branch information
BobdenOs and johannes-vogel authored Jun 17, 2024
1 parent 85ecf08 commit e17ddfd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,10 @@ class HANAService extends SQLService {
expands[this.column_name(x)] = x.SELECT.one ? null : []

const parent = src
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] })
this.extractForeignKeys(x.SELECT.where, parent.as, []).forEach(ref => {
const columnName = this.column_name(ref)
if (!parent.SELECT.columns.find(c => this.column_name(c) === columnName)) {
parent.SELECT.columns.push(ref)
}
})

Expand Down
2 changes: 1 addition & 1 deletion test/compliance/SELECT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('SELECT', () => {
const cqn = {
SELECT: {
from: { ref: ['complex.associations.unmanaged.Authors'] },
columns: [{ ref: ['ID'] }, { ref: ['static'], expand: ['*'] }]
columns: [{ ref: ['static'], expand: ['*'] }]
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +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;
static : Association to many Books on static.author = $self and static.ID > 0 and name != null;
}

0 comments on commit e17ddfd

Please sign in to comment.