cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Many-to-Many Association

martinkoch
SAP Champion
SAP Champion
4,431

Hi

is a many-to-many association possible with cds?

I am working with the new SAP Cloud Platform Business Application programming model. I didn't find anything in the respective documentation.

A simplified example:

Entity Book

Entity Author

One Book can have many Authors. One Author can have many books.

Thanks for your Help!

Best regards,

Martin

View Entire Topic
balbino_soaresferreirafil
Active Participant

Hello,

You I think you will need a entity to do the many-to-may relationship. For example:

entity Books{
        key id: Integer;
	name: String(100);
	authors: Association to many BooksAuthors on authors.book = $self;
	
}


entity BooksAuthors{
	key author: Association to Authors;
	key book: Association to Books
}


entity Authors{
	key id: Integer;
	name: String(100);
	books: Association to many BooksAuthors on books.author = $self;
}


aman_khanna
Advisor
Advisor

Many thanks, balbino.soaresferreirafilho

Was looking for something like this.

Quick check -

"books: Association to many BooksAuthors on books.book=$self;"

Shouldn't the above condition be books.author=$self ?

Or perhaps, I'm missing something?

balbino_soaresferreirafil
Active Participant
0 Kudos

Hi aman.khanna, you are correct! Thanks! it was a typo error.

0 Kudos

While I tried this,

getting the following error:

[ERROR] SQLITE_ERROR: table Books has no column named authors_ID. Any idea?

balbino_soaresferreirafil
Active Participant
0 Kudos

Check the upercase ID in your csv file used to import data. In my example the field is lowercase, so in the csv files try chage to authors_id