A link describes the association between one table and another.
Types of associations, also known as cardinalities, are listed below.
In the use interface, cardinalities are represented with a specific icon.
For join relations with a campaign table/database:
For join relations using Federated Database Access (FDA):
For more information on FDA tables, refer to Accessing an external database.
A link must be declared in the schema containing the foreign key of the table linked via the main element:
<element name="name_of_link" type="link" target="key_of_destination_schema">
<join xpath-dst="xpath_of_field1_destination_table" xpath-src="xpath_of_field1_source_table"/>
<join xpath-dst="xpath_of_field2_destination_table" xpath-src="xpath_of_field2_source_table"/>
...
</element>
Links obey the following rules:
The definition of a link is entered on a link-type <element>
with the following attributes:
name: name of link from the source table
target: name of target schema
label: label of link
revLink (optional): name of reverse link from the target schema (deduced automatically by default)
integrity (optional): referential integrity of the occurrence of the source table to the occurrence of the target table.
Possible values are:
revIntegrity (optional): integrity on the target schema (optional, “normal” by default)
revCardinality (optional): with value “single” populates cardinality with type 1-1 (1-N by default)
externalJoin (optional): forces the outer join
revExternalJoin (optional): forces the outer join on the reverse link
A link references one or more fields from the source table to the destination table. The fields making up the join ( <join>
element) need not be populated because they are automatically deduced by default using the internal key of the target schema.
An index is automatically added to the foreign key of the link in the extended schema.
A link consists of two half-links, where the first is declared from the source schema and the second is created automatically in the extended schema of the target schema.
A join can be an outer join if the externalJoin attribute is added, with the value “true” (supported in PostgreSQL).
As a standard, links are the elements declared at the end of the schema.
In the example below, we declare a 1-N relation to the “cus:company” schema table:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
...
<element label="Company" name="company" revIntegrity="define" revLabel="Contact" target="cus:company" type="link"/>
</element>
</srcSchema>
The schema generated:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<dbindex name="companyId">
<keyfield xpath="@company-id"/>
</dbindex>
...
<element label="Company" name="company" revLink="recipient" target="cus:company" type="link">
<join xpath-dst="@id" xpath-src="@company-id"/>
</element>
<attribute advanced="true" label="Foreign key of 'Company' link (field 'id')" name="company-id" sqlname="iCompanyId" type="long"/>
</element>
</schema>
The link definition is supplemented by the fields making up the join, i.e. the primary key with its XPath (“@id”) in the destination schema, and the foreign key with its XPath (“@company-id”) in the schema.
The foreign key is added automatically in an element that uses the same characteristics as the associated field in the destination table, with the following naming convention: name of target schema followed by name of associated field (“company-id” in our example).
Extended schema of the target (“cus:company”):
<schema mappingType="sql" name="company" namespace="cus" xtkschema="xtk:schema">
<element name="company" sqltable="CusCompany" autopk="true">
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>
...
<attribute desc="Internal primary key" label="Primary key" name="id" sqlname="iCompanyId" type="long"/>
...
<element belongsTo="cus:recipient" integrity="define" label="Contact" name="recipient" revLink="company" target="nms:recipient" type="link" unbound="true">
<join xpath-dst="@company-id" xpath-src="@id"/>
</element>
</element>
</schema>
A reverse link to the “cus:recipient” table was added with the following parameters:
In this example, we declare a link towards the “nms:address” schema table. The join is an outer join and is populated explicitly with the recipient’s email address and the “@address” field of the linked table (“nms:address”).
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
...
<element integrity="neutral" label="Info about email" name="emailInfo" revIntegrity="neutral" revLink="recipient" target="nms:address" type="link" externalJoin="true">
<join xpath-dst="@address" xpath-src="@email"/>
</element>
</element>
</srcSchema>
In this example, we create a 1-1 relation to the “cus:extension” schema table:
<element integrity="own" label="Extension" name="extension" revCardinality="single" revLink="recipient" target="cus:extension" type="link"/>
In this example, we declare a link to a folder (“xtk:folder” schema):
<element default="DefaultFolder('nmsFolder')" label="Folder" name="folder" revDesc="Recipients in the folder" revIntegrity="own" revLabel="Recipients" target="xtk:folder" type="link"/>
The default value returns the identifier of the first eligible parameter type file entered in the “DefaultFolder(‘nmsFolder’)” function.
In this example, we create a key on a link (“company” to “cus:company” schema) with the xlink attribute and a field of the (“email”) table:
<srcSchema name="recipient" namespace="cus">
<element name="recipient">
<key name="companyEmail">
<keyfield xpath="@email"/>
<keyfield xlink="company"/>
</key>
<attribute name="email" type="string" length="80" label="Email" desc="Recipient email"/>
<element label="Company" name="company" revIntegrity="define" revLabel="Contact" target="cus:company" type="link"/>
</element>
</srcSchema>
The schema generated:
<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
<element name="recipient" sqltable="CusRecipient">
<dbindex name="companyId">
<keyfield xpath="@company-id"/>
</dbindex>
<dbindex name="companyEmail" unique="true">
<keyfield xpath="@email"/>
<keyfield xpath="@company-id"/>
</dbindex>
<key name="companyEmail">
<keyfield xpath="@email"/>
<keyfield xpath="@company-id"/>
</key>
<attribute desc="Email address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
<element label="Company" name="company" revLink="recipient" target="sfa:company" type="link">
<join xpath-dst="@id" xpath-src="@company-id"/>
</element>
<attribute advanced="true" label="Foreign key of link 'Company' (field 'id')" name="company-id" sqlname="iCompanyId" type="long"/>
</element>
</schema>
The definition of the “companyEmail” name key was extended with the foreign key of the “company” link. This key generates a unique index on both fields.