cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAPM Association Modelling yielding inconsistent attribute names on foreign key joins

vijaygn1990
Explorer
0 Kudos

I have two entities defines as below

entity VoucherProgram: managed{

key PROGRAM_ID : UUID @(Core.Computed : true);

VOUCHER_DESC : String(2000);

VoucherDenomination : Association to many VoucherDenomination on VoucherDenomination.PROGRAM_ID = $self

}

entity VoucherDenomination: managed{

key DENOM_ID: UUID @(Core.Computed: true);

PROGRAM_ID: Association to VoucherProgram @assert.integrity; DENOMINATION: String(50)

}

In the above VoucherDenomination is generating foreign key constraint to PROGRAM_ID in voucherprogram.But the problem is VoucherDenom is having column name as PROGRAM_ID_PROGRAM_ID which establishes the foreign key constraint instead of PROGRAM_ID.My requirement is to have these two tables with PROGRAM_ID as foreign key

View Entire Topic
marcbecker
Contributor

To achieve what you want you need to use Unmanaged Associations with an explicit ON condition, instead of using Managed Associations, which automatically generate foreign key fields. You can read about the difference in the documentation:

CAP always also differentiates between the association and the actual foreign key. This means the foreign key value is never stored in the association, but always in a separate field.

entity VoucherDenomination: managed{
  key DENOM_ID: UUID @(Core.Computed: true);
  PROGRAM_ID: UUID; // foreign-key
  PROGRAM: Association to VoucherProgram @assert.integrity on PROGRAM.PROGRAM_ID = PROGRAM_ID
  DENOMINATION: String(50)
}

With slightly different naming of your ID In the entity VoucherProgram, as suggested also by Gregor you could leverage also managed Associations with a more consistent naming pattern:

entity VoucherProgram: managed {
  key ID: UUID;
  ...
}

entity VoucherDenomination: managed {
  ...
  PROGRAM: Association to VoucherProgram; // implicitly creates foreign key PROGRAM_ID
}