2

CAP double foreign key issuse

 1 year ago
source link: https://answers.sap.com/questions/13751191/cap-double-foreign-key-issuse.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
9 minutes ago

CAP double foreign key issuse

4 Views

Hello experts,

I'm having a problem with a rather particular schema: I have a table (DocumentItem) which represents all the items that are in "DocumentHeader". The primary keys are:

- DocumentHeader -> DocumentId

- DocumentItem -> DocumentId * (foreign key) and ItemNumber

The problem comes when in another table I need DocumentId (taken from DocumentHeader) and ItemNumber (taken from DocumentItem) as foreign keys. I also need that the ItemNumber is correctly associated with the DocumentID, as declared in the "DocumentItem" table

The problem in question is that it doesn't show me when I go to insert "ItemNumber" mock data, going to show it only if I remove the "key" property.

Thanks to all, I am available for clarification

general schema:

image.png

schema.cds

entity DocumentHeader
{
    key DocumentId : String
        @Core.Computed;
    Status : String(100) not null;
    CustomerId : String(100) not null;
    TotalValue : Double not null;
    Currency : String(100) not null;
    TotalQuantity : Double not null;
    UoM : String(100) not null;
    to_DeliveryAddress : Association to one Customer
        @assert.integrity;
    DocumentDate : String(100) not null;
    CustomerOrder : String(100) not null;
    RequestDeliveryDate : String(100) not null;
    EffectiveDeliveryDate : String(100) not null;
    DeliveryStatus : String(100) not null;
    DeliveryBloc : String(100) not null;
    IncoiceBloc : String(100) not null;
    PayConditions : String(100) not null;
    ShipToPartnerId : String(100) not null;
    to_DocumentItems : Association to many DocumentItem
        @assert.integrity;
    to_Partners : Association to many Partner on to_Partners.DocumentId = $self
        @assert.integrity;
    to_PriceConditions : Association to many PriceCondition on to_PriceConditions.DocumentId = $self
        @assert.integrity;
    to_DeliveryPlans : Association to many DeliveryPlan on to_DeliveryPlans.DocumentId = $self
        @assert.integrity;
    to_Notes : Association to many Note on to_Notes.DocumentId = $self;
}

entity Note
{
    key NoteType : String
        @Core.Computed;
    NoteDesc : String(100) not null;
    NoteText : String(100) not null;
    key ItemNumber : Association to one DocumentItem
        @assert.integrity;
    DocumentId : Association to one DocumentHeader;
}

entity DocumentItem
{
    key ItemNumber : String
        @Core.Computed;
    ProductId : String(100) not null;
    Quantity : Double not null;
    UoM : String(100) not null;
    Price : Double not null;
    Currency : String(100) not null;
    Discounts : Double not null;
    TotalValue : Double not null;
    ItemStatus : String(100) not null;
    Incoterms : String(100) not null;
    EffectiveGoodIssue : String(100) not null;
    DeliveryStatus : String(100) not null;
    ItemCategory : String(100) not null;
    BatchStatus : String(100) not null;
    ATPDate : String(100) not null;
    key DocumentId : Association to one DocumentHeader
        @assert.integrity;
    to_Partners : Association to many Partner on to_Partners.ItemNumber = $self
        @assert.integrity;
    to_PriceConditions : Association to many PriceCondition on to_PriceConditions.ItemNumber = $self
        @assert.integrity;
    to_DeliveryPlans : Association to many DeliveryPlan on to_DeliveryPlans.ItemNumber = $self
        @assert.integrity;
    to_Notes : Association to many Note on to_Notes.ItemNumber = $self;
}

Mock Data ("ItemNumber" is missing):

image.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK