diff --git a/db-service/lib/search.js b/db-service/lib/search.js index 83675ccdc..57a6b87d6 100644 --- a/db-service/lib/search.js +++ b/db-service/lib/search.js @@ -114,7 +114,7 @@ const _getSearchableColumns = entity => { deepSearchCandidates.forEach(c => { const element = c.ref.reduce((resolveIn, curr, i) => { const next = resolveIn.elements?.[curr] || resolveIn._target.elements[curr] - if (next.isAssociation && !c.ref[i + 1]) { + if (next?.isAssociation && !c.ref[i + 1]) { const searchInTarget = _getSearchableColumns(next._target) searchInTarget.forEach(elementRefInTarget => { searchableColumns.push({ ref: c.ref.concat(...elementRefInTarget.ref) }) diff --git a/db-service/test/bookshop/db/search.cds b/db-service/test/bookshop/db/search.cds index e916d665a..bbb2ddc00 100644 --- a/db-service/test/bookshop/db/search.cds +++ b/db-service/test/bookshop/db/search.cds @@ -7,6 +7,7 @@ entity Books { coAuthor_ID_unmanaged : Integer; coAuthorUnmanaged : Association to Authors on coAuthorUnmanaged.ID = coAuthor_ID_unmanaged; + shelf : Association to BookShelf; } @cds.search: {author.lastName} @@ -70,3 +71,14 @@ entity CalculatedAddresses : Addresses { entity CalculatedAddressesWithoutAnno : Addresses { calculatedAddress : String = street || ' ' || zip || '' || city } + +@cds.search: { + genre, + books.doesNotExist +} +entity BookShelf { + key ID : Integer; + genre : String; + books : Composition of many Books + on books.shelf = $self; +} diff --git a/db-service/test/cqn4sql/search.test.js b/db-service/test/cqn4sql/search.test.js index 1887265e2..be44de4d0 100644 --- a/db-service/test/cqn4sql/search.test.js +++ b/db-service/test/cqn4sql/search.test.js @@ -275,6 +275,20 @@ describe('search w/ path expressions', () => { } where search((authorWithAddress.note, address.city), 'x')` expect(JSON.parse(JSON.stringify(res))).to.deep.equal(expected) }) + + it('dont dump for non existing search paths, but ignore the path', () => { + let query = CQL`SELECT from search.BookShelf { ID, genre }` + query.SELECT.search = [{ val: 'Harry Plotter' }] + + let res = cqn4sql(query, model) + const expected = CQL` + SELECT from search.BookShelf as BookShelf + { + BookShelf.ID, + BookShelf.genre + } where search((BookShelf.genre), 'Harry Plotter')` + expect(JSON.parse(JSON.stringify(res))).to.deep.equal(expected) + }) }) describe('calculated elements', () => {