on 01-13-2024 7:18 AM
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
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.