Relations join together two datasources, for example a CUSTOMERS and a ORDERS table. Through [RelationItems] the nature of the link between the datasources is defined, for example to link the CUSTOMERS and ORDERS table based on the customer_id column.
Relations return a JSFoundSet object.
Relations are used in Solutions to display related data, for example using a [Field], a TabPanel or a Portal or to work with related data in business logic.
There are several possible Relation configuration that make a Relation special
Relations that contain only RelationItems based on global variables on the source side, thus no dependency on the source table are considered global relations.
Global relations can be used to get a limited FoundSet, for example all active customers, by adding a relation item that specifies that the "active" flag in the CUSTOMERS table has to be equal to a certain global variable. For example, if the CUSTOMERS table contains a column called "is_active" of type INTEGER and a default value of 1 indicating it is an active record, the following would create a global realtion that returns a FoundSet with all active customers:
var ACTIVE = 1;
Relations can use the same table as primary and foreign table. Depending on the setup of the the RelationItems the relation can point back to the originating record or one or more different records.
If the primary and foreign table are equal and the relation does not contain any RelationItems, it becomes a Container relation. A Container relation returns it originating FoundSet. A Container relation can be used to set the FoundSet of the parent form into the Form displayed in a TabPanel.
When defining a relation, there are a several settings that influence the behavior of the Relation under different circumstances.
Allow creation of related records:
When true: the execution of "customers_to_orders.newRecord()" will create a new record.
When false: trying to create a new record over the relation will throw a ServoyException.NO_RELATED_CREATE_ACCESS exception.
Allow parent delete when having related records:
When true: when there are related order records, Servoy will block the delete of the customer record and raise a ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS exception.
When false: related records will not block the delete of the parent record
Delete related records:
When true: when the customer record is deleted and there are related records in the orders table, those order records will also get deleted.
When false: related records will remain untouched.
The option Allow parent delete when having related records overrules the option Delete related records, meaning that you set the first option to false, the value of the latter option will be ignored.
{column:width=80px}{column}{column}{column}
Property Summary
allowCreationRelatedRecords
Flag that tells if related records can be created through this relation.
allowParentDeleteWhenHavingRelatedRecords
Flag that tells if the parent record can be deleted while it has related records.
deleteRelatedRecords
Flag that tells if related records should be deleted or not when a parent record is deleted.
foreignTable
Qualified name of the foreign data source.
initialSort
A String which specified a set of sort options for the initial sorting of data
retrieved through this relation.
primaryTable
Qualified name of the primary data source.
{column:width=100%}{column}
Property Details
Flag that tells if related records can be created through this relation.
The default value of this flag is "false".
Parameters
Also see
External links
Sample
Flag that tells if the parent record can be deleted while it has related records.
The default value of this flag is "true".
Parameters
Also see
External links
Sample
Flag that tells if related records should be deleted or not when a parent record is deleted.
The default value of this flag is "false".
Parameters
Also see
External links
Sample
Qualified name of the foreign data source. Contains both the name of the foreign
server and the name of the foreign table.
Parameters
Also see
External links
Sample
A String which specified a set of sort options for the initial sorting of data
retrieved through this relation.
Has the form "column_name asc, another_column_name desc, ...".
Parameters
Also see
External links
Sample
The join type that is performed between the primary table and the foreign table.
Can be "inner join" or "left outer join".
Parameters
Also see
External links
Sample
The name of the relation.
Parameters
Also see
External links
Sample
Qualified name of the primary data source. Contains both the name of the primary server
and the name of the primary table.
Parameters
Also see
External links
Sample