ITableForeignKey.RTableObject

Fore Syntax

RTableObject: ITable;

Fore.NET Syntax

RTableObject: Prognoz.Platform.Interop.Db.ITable;

Description

The RTableObject property determines the table to which the external key refers.

Comments

To create external key use the ITableForeignKeys.Add.

Fore Example

Executing the example requires tables with the TABLE and TABLE_FK identifiers in repository. The TABLE table must contain the primary key with the ID identifier. The TABLE_FK table must contain an integer field with the FK identifier.

Add links to the Db and Metabase system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    Table, TableFK: ITable;
    FKeys: ITableForeignKeys;
    Key: ITableForeignKey;
Begin
    // Obtain a repository
    mb := MetabaseClass.Active;
    // Obtain a table
    Table := mb.ItemById("TABLE").Edit As ITable;
    // Get second table
    TableFK := mb.ItemById("TABLE_FK").Edit As ITable;
    // Obtain a collection of external keys of the "TABLE" table
    FKeys := Table.ForeignKeys;
    // Delete external keys of the "TABLE" table
    FKeys.Clear;
    // Add external key to the "TABLE" table
    Key := FKeys.Add;
    { Set the "FK" field of the "TABLE_FK" table as external key
      "TABLE" table }

    Key.Columns := "FK";
    Key.RTableObject := TableFK;
    Key.RColumns := "ID";
    // Save changes
    (Table As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the FK field of the TABLE_FK table is an external key for the TABLE table.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Db;

Public
 Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Table, TableFK: ITable;
    FKeys: ITableForeignKeys;
    Key: ITableForeignKey;
Begin
    // Obtain a repository
    mb := Params.Metabase;
    // Obtain a table
    Table := mb.ItemById["TABLE"].Edit() As ITable;
    // Get second table
    TableFK := mb.ItemById["TABLE_FK"].Edit() As ITable;
    // // Obtain a collection of external keys of the "TABLE" table
    FKeys := Table.ForeignKeys;
    // Delete external keys of the "TABLE" table
    FKeys.Clear();
    // Add external key to the "TABLE" table
    Key := FKeys.Add();
    { Set the "FK" field of the "TABLE_FK" table as external key
      "TABLE" table }

    Key.Columns := "FK";
    Key.RTableObject := TableFK;
    Key.RColumns := "ID";
    // Save changes
    (Table As IMetabaseObject).Save();
End Sub;

See also:

ITableForeignKey