cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create entity based on another entity

dpk_bhat76
Product and Topic Expert
Product and Topic Expert
0 Likes
1,553

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 ?

Accepted Solutions (0)

Answers (2)

Answers (2)

norbert_laenger2
Discoverer

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

dpk_bhat76
Product and Topic Expert
Product and Topic Expert
0 Likes

Thanks alot. Trying it out right away.

norbert_laenger2
Discoverer

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

dpk_bhat76
Product and Topic Expert
Product and Topic Expert
0 Likes

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?