Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(search): ignore invalid path expressions inside @cds.search #849

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db-service/lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
12 changes: 12 additions & 0 deletions db-service/test/bookshop/db/search.cds
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
}
14 changes: 14 additions & 0 deletions db-service/test/cqn4sql/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down