Skip to Content
1
Aug 20, 2019 at 02:17 PM

Counting associated entities using CDS

2738 Views Last edit Aug 20, 2019 at 02:27 PM 2 rev

Hi,

Is there a way to count the number of associated entities using CDS? Let's say I'd like to display the number of books written by a particular author:

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

  entity Authors {
    key ID : Integer;
    name   : String;
    books  : Association to many Books on books.author = $self;
    @Core.Computed
    numberOfBooks : Integer;
  }

I tried something like count(books) as numberOfBooks but it's not supported :-)

Cheers,

Pierre