I am working on a project to move some legacy APPs to BTP using CAP. Here is the issue I am facing and I didn't found a solution for it.
There are some ID fields in both entities, business doesn't want to use UUID, but use the old logic in the legacy system. So we use customer handler to populate the IDs.
the CDS like below, just explain the code, not exactly the same.
entity Books {
key ID : Integer;
title : String;
Serials : Composition of many Books_Serial on Serials.book = $self;
}
entity Books_Serial{
key book : Association to Books;
key serial_ID : Integer;
serial_title : String;
}
and we create a customer handler to populate the ID for both entity
this.before('CREATE','Books', req =>{
//generate ID
})
this.before('CREATE','Books_Serial', req =>{
//generate serial_ID
})
when I using POST to insert the data for each entity, the customer handlers are triggered.
but when I post the Books with the deep structure, the Books_Serial handler is not triggered, only Books handler is triggered.
I suppose both handlers should work because it will insert the data to both entity tables in the backend DB, but it doesn't.
Since I am new to CAP model, and this is my first hands on work, please help me out.
Thank you very much.
Request clarification before answering.
Hi Abe Dong,
Yes, only the "BEFORE" handler of the parent entity is called for a deep entity insert.
In your example, you can handle the serial_id for the "Books_Serial" through the composition (Serials) you defined in the "Books" Entity.
this.before('CREATE','Books', context =>{
//generate ID
const ID = context.data.ID || await _generateID();
const serialID = await _generateSerialID();
// Set ID of Books
context.data.ID = ID;
// Set the Serial ID of ALL Books_Serial through the composition
context.data.Serials.forEach(bookSerial => bookSerial.serial_ID = serialID)
})
Hope this helps.
Regards,
John
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 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.