Many-many association example
Nandanchaturvedi opened this issue · 5 comments
Hi colleagues
I request you to provide a working example showing many-many relation in CAP. This seems to be a fundamental requirement for any business application and I dont see any documentation describing it for reference.
Request you to share.
Hi @Nandanchaturvedi ,
Please refer to the documentation: https://cap.cloud.sap/docs/guides/domain-models#managed-many-to-many-associations
Best regards,
David
Hi @David-Kunz ,
I would request if there is an example which you can share. I referred the documentation but facing some issues as I opened another issue in the Github earlier for the same.
Do you have a repo showing working example with many-many
HI @Nandanchaturvedi ,
Unfortunately, I don't have a concrete example, but did you try the example from the documentation?
entity Authors { ...
books : Association to many Books2Authors on books.author = $self;
}
entity Books { ...
author : Association to many Books2Authors on author.book = $self;
}
entity Books2Authors { ...
book : Association to Books;
author : Association to Authors;
}
Best regards,
David
Hi @David-Kunz ,
Yes, I did try this but not sure how this would work in the context of creation and in Fiori.
Following is the error I get if I try the deep insert.
While I try to make all IDs Guid, I get the following error:
{
"error": {
"code": "400",
"message": "Deep insert with to-many Associations is not allowed"
}
}
This is how the model looks like:
entity PfgRequests : managed, cuid {
contacts : Association to many PfgContacts on contacts.pfgRequest = $self;
}
entity Contacts : cuid {
pfgRequests : Association to many PfgContacts on pfgRequests.contact = $self;
}
entity PfgContacts { //maintains many-many entity
key pfgRequest: Association to PfgRequests;
key contact: Association to Contacts;
}
And I have exposed all three in the service
Hi @Nandanchaturvedi ,
It's not allowed to deep insert too many associations.
You need to do the posts on each entity.
Best regards,
David