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 · 2 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
@daogrady
Copy link
Contributor

Hi @mutschosW ,

you seem to be using a .where fragment within a projection. I don't think I have ever seen this syntax and I couldn't find it in CAPire either. Could you please point me to where you found this syntax?

Best,
Daniel

@mutschosW
Copy link
Author

Hi @daogrady ,

I also cannot find any code example, but it is the only working possibility I have found for realising the infix filter

b.suppliers`[city='Paris']`

in Typescript. Have I overseen another solution?

Best regards,
Marcel

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

2 participants