cancel
Showing results for 
Search instead for 
Did you mean: 

Custom name for managed Composition/Association

mvoros
Active Contributor
0 Kudos
759

Hi,

this may sound stupid but I find it really annoying how the names are generated for properties related to managed associations/compositions. E.g. if I have something like this:

group : Association to PromotionGroups;

it generates property group_id. This is documented in CAP documentation. My problem is that all properties use camel case names but just these properties use _. Even the properties added automatically by draft handling have nice names like IsActiveEntity.

I don't see any way how to change this in CAP documentation. Is there a way? If I switch to unmanaged association/composition where I can define my own property, what do I lose? I know that I will lose foreign keys. Is there anything else? Are managed association really that beneficial? I have to provide nicer error messages for these fields anyway so I will have a logic for validation in the service layer anyway.

Or is there any other way how to provide nicer names for these properties?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

hjb
Product and Topic Expert
Product and Topic Expert

Hi Martin, you probably want to read my answer from 2021 to this question: https://answers.sap.com/questions/13302506/rename-a-column-generated-by-sap-cap-cds.html?childToView...

Regards, Hans-Joachim

mvoros
Active Contributor
0 Kudos

Hi,

thanks, that's exactly the same question. As far as I understand, it's just more work and missing foreign key. but I think ability to publish UI with consistent names may be worth it. Is there a way to manually define FOREIGN KEY via annotations?

Thanks

hjb
Product and Topic Expert
Product and Topic Expert
0 Kudos

No there is no way to rename elements via annotations and there won't be one. Please use unmanaged associations to have full control over your naming scheme.

mvoros
Active Contributor
0 Kudos

No, I am asking if it there is a way to define FOREIGN KEY constrain on any field via annotations? I understand that property name for managed association cannot be changed.

Thanks

hjb
Product and Topic Expert
Product and Topic Expert
0 Kudos

Oh, sorry then I misread your last question. You mean referential constraints? They are automatically added for associations but not controllable via annotation. But you are free to add your own constraints via hdbconstraint.

mvoros
Active Contributor
0 Kudos

OK, so at this moment there is no generic way (e.g. via annotations) to define referential constraints in CDS. It would be nice to have it so it's then valid for all DBs.


Once again, thanks for your comments

hjb
Product and Topic Expert
Product and Topic Expert

Martin,

do you know that we already generate referential constraints for managed associations as described in the capire documentation on constraints and that in the most generic way there is no need to decorate associations with 'constraint' annotations?

We have put a lot of thought into the design to let a highly complex database operation appear easy for the user. One of the prerequisites for constraints are that they comprehend the full primary key tuple of the 'leading' entity. Therefore we decided to create managed constraints with one consistent behaviour for managed associations only.

Regarding your "for all databases": Constraints are generated for SQLite and SAP HANA.

BTW, our constraints are 'initially deferred' which means that they won't be enforced on already existing content. This way we allow to add DB constraints later on without locking up the deployment.

Feel free to ask if you have open questions.

HTH

Answers (0)