Skip to main content

Notifications

AddForeignKeyRelation using table relation property relatedTableRole. When and how to use it

AddForeignKeyRelation using table relation property relatedTableRole. When and how to use it

Initial demo setup


CustTableMaster Table having three foreign keys [CustAccount1, CustAccount2, CustAccount3] added. All keys point to CustTable
CustTable master form having CustTableMaster as primary DS and additional Custable1, Custable2, Custable3 datasources outer joined to CustTableMaster

BlogPost_5F00_002_5F00_001.png

Test data in CustTableMaster

BlogPost_5F00_002_5F00_002.png

CustAccount1

CustAccount2

CustAccount3

dataAreaId

recVersion

Partition

RecId

US-001

US-002

US-003

usmf

1

5637144576

5637144576

US-004

US-005

US-006

usmf

1

5637144576

5637144577

Notice that:

First row Custaccount1 points to US-001,Custaccount2 points to US-002,Custaccount3 points to US-003

Second row Custaccount1 points to US-004,Custaccount2 points to US-005,Custaccount3 points to US-006

Open CustTableMaster Form:

BlogPost_5F00_002_5F00_003.png

CustTableMaster_CustAccount1

CustTableMaster_CustAccount2

CustTableMaster_CustAccount3

CustTable1_AccountNum

CustTable2_AccountNum

CustTable3_AccountNum

US-001

US-002

US-003

US-001 (correct)

US-001 (wrong)

US-001 (wrong)

US-004

US-005

US-006

US-004 (correct)

US-004 (wrong)

US-004 (wrong)

Notice that:

First row CustTable1_AccountNum points to US-001,CustTable2_AccountNum points to US-001 instead of US-002,CustTable3_AccountNum points to US-001 instead of US-003

Second row CustTable1_AccountNum points to US-004,CustTable2_AccountNum points to US-004 instead of US-005,CustTable3_AccountNum points to US-004 instead of US-006

Rename table relation roles

For example first role should be renamed to CustTable_CustAccount_Role1 and all others accordingly:

BlogPost_5F00_002_5F00_004.png

If UseDefaultRoleNames = Yes default name infering would be ussed. See Role names inferring for more information

In CustTableMaster form Overide init of these DS'es: CustTable1,CustTable2,CustTable3:

BlogPost_5F00_002_5F00_005.png

public void init()
{
    super();
    this.query().dataSourceName(this.name()).clearLinks();
    this.query().dataSourceName(this.name()).addForeignkeyRelation(identifierStr(CustTable_CustAccount_Role1));
}

Final  CustTableMaster form result

BlogPost_5F00_002_5F00_006.png

CustTableMaster_CustAccount1

CustTableMaster_CustAccount2

CustTableMaster_CustAccount3

CustTable1_AccountNum

CustTable2_AccountNum

CustTable3_AccountNum

US-001

US-002

US-003

US-001 (correct)

US-002 (correct)

US-003 (correct)

US-004

US-005

US-006

US-004 (correct)

US-005 (correct)

US-006 (correct)

More information with of role names inferring


The following defaulting mechanism can be used for role names without having to fill out the two properties (by leaving
them blank and marking UseDefaultRoleNames to yes):
(1) <related table name> is used as the RelatedTableRole

Be aware, that you should not use UseDefaultRoleNames as it will result in conflicts in between relatedTableRoles of relations.

Hands on example

Put UseDefaultRoleNames = yes for CustAccount1 relation:

BlogPost_5F00_002_5F00_007.png

Now manually alter CustAccount2 RelatedTable role to CustTable

BlogPost_5F00_002_5F00_008.png

Compiling table throws error:

BlogPost_5F00_002_5F00_009.png

Clear CustAccount2 RelatedTable role to and set UseDefaultRoleNames to yes

BlogPost_5F00_002_5F00_010.png

Compiler throws error about conflicts between CustAccount1 and CustAccount2 roles

BlogPost_5F00_002_5F00_011.png

Comments