Johan Vergeer
Johan Vergeer

Reputation: 5578

Add relations to dataset dynamically in Progress OpenEdge

I would like to create a dataset that only contains the temp-tables, and where the relations will be defined later.

When I define the relations in the dataset everything works fine

DEF TEMP-TABLE ttParent NO-UNDO 
    FIELD pKey       AS INT
    FIELD parentName AS CHAR.

DEF TEMP-TABLE ttChild NO-UNDO
    FIELD iParent   AS INT  XML-NODE-TYPE "HIDDEN"
    FIELD childName AS CHAR. 

DEF DATASET dsMyDataset
    FOR ttParent, ttChild

    DATA-RELATION Parent_Child FOR ttParent, ttChild
    RELATION-FIELDS(pKey, iParent)
    NESTED FOREIGN-KEY-HIDDEN.

CREATE ttParent.
ASSIGN
    ttParent.pKey       = 1
    ttParent.parentName = "Parent".

CREATE ttChild.
ASSIGN
    ttChild.iParent   = ttParent.pKey
    ttChild.childName = "Child".

CREATE ttChild.
ASSIGN
    ttChild.iParent   = ttParent.pKey
    ttChild.childName = "Child2".

DATASET dsMyDataset:WRITE-XML("FILE", "C:/temp/testDs.xml").

This creates the following XML as expected:

<?xml version="1.0"?>
<dsMyDataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ttParent>
        <pKey>1</pKey>
        <parentName>Parent</parentName>
        <ttChild>
            <childName>Child</childName>
        </ttChild>
        <ttChild>
            <childName>Child2</childName>
        </ttChild>
    </ttParent>
</dsMyDataset>

Now when I rewrite this into a dataset where only the temptables are defined and the relations are added later:

// Definition of temp-tables same as above

DEF DATASET dsMyDynamicDataset
    FOR ttParent, ttChild.

DATASET dsMyDynamicDataset:ADD-RELATION (
    BUFFER ttParent:HANDLE, BUFFER ttChild:HANDLE,
    "pKey,iParent",
    FALSE, TRUE, FALSE, FALSE, TRUE).

// Filling of temp-tables same as above

DATASET dsMyDynamicDataset:WRITE-XML("FILE", "C:/temp/testDs.xml").

I would expect the same result as above but this is the result I get instead:

<?xml version="1.0"?>
<dsMyDynamicDataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ttParent>
        <pKey>1</pKey>
        <parentName>Parent</parentName>
    </ttParent>
    <ttChild>
        <childName>Child</childName>
    </ttChild>
    <ttChild>
        <childName>Child2</childName>
    </ttChild>
</dsMyDynamicDataset>

Upvotes: 1

Views: 1274

Answers (1)

TheDrooper
TheDrooper

Reputation: 1217

You have the relation set to inactive. The third logical parameter in the ADD-RELATION statement is "not-active". When false, the relation is created but not activated. Change that parameter to true and you'll get the expected output.

Here is the Progress documentation on ADD-RELATION:

https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/add-relation(-)-method.html

Upvotes: 2

Related Questions