Simplified Extension Example
This commit is contained in:
44
db/assoc_extension.cds_
Normal file
44
db/assoc_extension.cds_
Normal file
@@ -0,0 +1,44 @@
|
||||
using {sap.capire.bookshop} from '_base/db/schema';
|
||||
using {sap.capire.orders} from '_base/db/schema';
|
||||
using from '_base/db/capire_common';
|
||||
//using {Z_bookshop.fieldExtension as field} from './field_extension';
|
||||
|
||||
using {
|
||||
cuid, managed, Country, sap.common.CodeList
|
||||
} from '@sap/cds/common';
|
||||
|
||||
|
||||
|
||||
namespace Z_bookshop.assocExtension;
|
||||
|
||||
|
||||
// extend existing entity
|
||||
extend orders.Orders with {
|
||||
Z_Customer : Association to one Z_Customers;
|
||||
Z_SalesRegion : Association to one Z_SalesRegion;
|
||||
}
|
||||
|
||||
// new entity - as association target
|
||||
entity Z_Customers : cuid, managed
|
||||
{
|
||||
email : String;
|
||||
firstName : String;
|
||||
lastName : String;
|
||||
creditCardNo : String;
|
||||
dateOfBirth : Date;
|
||||
status : String @assert.range enum {platinum; gold; silver; bronze} default 'bronze';
|
||||
creditScore : Decimal @assert.range: [ 1.0, 100.0 ] default 50.0;
|
||||
|
||||
}
|
||||
|
||||
// new unique constraint (secondary index)
|
||||
annotate Z_Customers with @assert.unique: { email: [ email ] }
|
||||
{
|
||||
email @mandatory; // mandatory check
|
||||
}
|
||||
|
||||
|
||||
// new entity - as code list
|
||||
entity Z_SalesRegion: CodeList {
|
||||
key regionCode : String(11);
|
||||
}
|
||||
Reference in New Issue
Block a user