cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Entity Items by grouping by associations CAP CDS?

0 Kudos

This is my data-model.cds:

    entity Authors : {
      key ID : UUID;
      name : String(111);
      books : Association to many Books on books.author = $self;
    }

    entity Books : {
      key ID : UUID;
      author : Association to Authors;
      title : String;
}

How can i get JSON with oData query to group all books under each author?

So for example for author "John Doe" i will get all related books and for "Emily" all of her books?
Heres the wanted result:

{
"John Doe": [
{id:1,title: "first book"},
{id:2,title: "second book"} ], "Emily ": [ {id:3,title: "Harrry poter"}, {id:4,title: "second Harrry"} ] }
View Entire Topic
pierre_dominique2
Contributor

You can use the $expand parameter for this: Serving OData APIs

EDIT: add link to the documentation

0 Kudos

Works Great!
heres the url that i'v needed:
<service>admin/Authors?$expand=books($select=ID,title)