on ‎2023 Mar 24 5:09 PM
Hello CAP experts!
I have a requirement to create 2 entities with many common attributes. So is there any way we can create a parent entity and inherit that to different entities ? Or what is the most optimal way to achieve such requirement ?
Request clarification before answering.
Hi,
sounds to me like the 7 attributes that are shared between the A and B should be an named aspect...
This should look like this: capire - Domain Modeling with CDS (cloud.sap)
The attributes bouth entities need would be a named aspect an both entities A and B using this context.
So both entities share the attributives (on design time and Annotation level) but each entity will have it own lifetime and is saved/change without dependencies.
regards
Norbert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think it depends a lot on the "lifetime" of the entities.
Referring to you description I would assume you entities have different lifetime and exist an its own.
So they can be changed/delete without effecting the other entity? And both entities should not know eachother?
The only thing is, when create entity A, B should be also created and wen creation B, A should be created?
And you only want to copy the same data to the other entity?
I this is this case I just would create/insert the other entity when one is created.
As you said they share most attributes.
I hope this helps, regards
Norbert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Norbert!
Thanks a lot for the response.
Let me put some more context:
Entity A and B have totally different lifetimes
We already have a DB with Entity A with around 17 fields.
Now we have a new requirement for entity B.
B needs 4 extra attributes other than that of A.
7 attributes of A are irrelevant for B.
10 attributes are common among A and B.
So I was thinking if I can create an entity C, with only common attributes. And if possible, some how inherit C and create A and B?
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 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.