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

[BUG] Cannot use a 'where' statement on a projection used in SELECT.from(...).columns() #203

Open
1 task done
mutschosW opened this issue Aug 15, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@mutschosW
Copy link

mutschosW commented Aug 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I use the projection syntax in a SELECT to expand associations. Unfortunately, the proposed solution at the CAP documentation (combination of projection and tagged template strings) is not valid TypeScript syntax. Here the example from the documentation:

SELECT.from ('Authors', a => {
   a.ID, a.name, a.books (b => {
     b`.*`, 
     b.suppliers`[city='Paris']`('*')
   })
})

I tried a workaround which is working:

SELECT.from ('Authors', (a) => [
   a.ID, a.name, a.books ((b) => [
     b('.*'), 
     (b.suppliers((s) => [s('*')]) as SELECT<unknown>).where(`city = 'Paris'`)
  ])
])

but unfortunately a cast to SELECT<unknown> is necessary.

Expected Behavior

The expected behaviour is allowing the "where" w/o casting:

SELECT.from ('Authors', (a) => [
   a.ID, a.name, a.books ((b) => [
     b('.*'), 
     b.suppliers((s) => [s('*')]).where(`city = 'Paris'`)
  ])
])

References

https://cap.cloud.sap/docs/node.js/cds-ql#columns

Versions

Package Version
Node.js v20.11.0
@sap/cds 7.9.2
@sap/cds-compiler 4.9.4
@sap/cds-dk 7.9.2
@sap/cds-dk (global) 7.6.0
@sap/eslint-plugin-cds 3.0.3
@sap/cds-mtxs 1.18.0
@cap-js/cds-types 0.2.0

Anything else? Logs?

I can also contribute if you need.

@mutschosW mutschosW added the bug Something isn't working label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant