2024 Feb 16 1:02 PM - edited 2024 Feb 16 1:07 PM
Hello experts,
I've been trying different ways of ordering by a certain column on a path expression while using CAP v7 with NodeJS and I have not been successful yet.
I've searched through the documentation but unfortunately was not able to find a similar case to mine.
Given the following example and supposing that the authors projection has a column named age :
let books = await SELECT.from('Books').columns(books => {
books `*`,
books.authors('*')
}).where({ID : 1});
How can I order all the authors from the book with ID = 1 by age ?
I've tried the following:
let books = await SELECT.from('Books').columns(books => {
books `*`,
books.authors('*').orderBy('age desc')
}).where({ID : 1});
But this leads to the following error :
[cds] - TypeError: Cannot read properties of undefined (reading 'age')
Is there any possible way I can order authors by a column in this case?
Thanks!
Request clarification before answering.
This might be what you are looking for from syntax perspective:
let books = await SELECT.from('Books').columns(books => {
books `*`,
books.authors('*')`[order by age desc]`
}).where({ID : 1});
This is extended from the syntax for infix filters. But, I'm not sure if that sorts the inner array as you are expecting. My guess is sorting is not yet supported.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.