Skip to content

Commit

Permalink
fix: pass context of navigation for list within infix filter (#433)
Browse files Browse the repository at this point in the history
the base definition needs to be passed to recursive calls, or else
resolving references following assocs to different entities may fail.
  • Loading branch information
patricebender authored Jan 31, 2024
1 parent 2ebf783 commit 0ca077f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ function cqn4sql(originalQuery, model = cds.context?.model || cds.model) {
transformedTokenStream.push({ list: [] })
}
} else {
transformedTokenStream.push({ list: getTransformedTokenStream(token.list) })
transformedTokenStream.push({ list: getTransformedTokenStream(token.list, $baseLink) })
}
} else if (tokenStream.length === 1 && token.val && $baseLink) {
// infix filter - OData variant w/o mentioning key --> flatten out and compare each leaf to token.val
Expand Down
35 changes: 35 additions & 0 deletions db-service/test/cqn4sql/table-alias.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,41 @@ describe('table alias access', () => {
expect(res).to.deep.equal(expected)
})

it('handles ref in list of from with scoped query', () => {
const query = SELECT.from({
ref: [
{
id: 'bookshop.Books',
where: [
{ list: [{ ref: ['dedication', 'addressee', 'ID'] }] },
'in',
CQL`SELECT Books.ID from bookshop.Books as Books where Books.ID = 5`,
],
},
'coAuthorUnmanaged',
],
}).columns('ID')

const list = [
{
list: [{ ref: ['Books', 'dedication_addressee_ID'] }],
},
'in',
CQL`SELECT Books.ID from bookshop.Books as Books where Books.ID = 5`,
]

const expected = SELECT.from('bookshop.Authors as coAuthorUnmanaged').columns('coAuthorUnmanaged.ID').where(`
exists (
SELECT 1 from bookshop.Books as Books where coAuthorUnmanaged.ID = Books.coAuthor_ID_unmanaged
)
`)

expected.SELECT.where[1].SELECT.where.push('and', ...list)

const res = cqn4sql(query, model)
expect(res).to.deep.equal(expected)
})

it('handles value subquery in WHERE', () => {
let query = cqn4sql(
CQL`SELECT from bookshop.Books { ID }
Expand Down

0 comments on commit 0ca077f

Please sign in to comment.