4D v14.3

RELATE ONE

Home

 
4D v14.3
RELATE ONE

RELATE ONE 


 

RELATE ONE ( manyTable | Field {; choiceField} ) 
Parameter Type   Description
manyTable | Field  Table, Field in Table for which to establish all automatic relations, or Field with manual relation to one table
choiceField  Field in Choice field from the one table

RELATE ONE has two forms.

The first form, RELATE ONE(manyTable), establishes all automatic Many-to-One relations for manyTable in the current process. This means that for each field in manyTable that has an automatic Many-to-One relation, the command will select the related record in each related table. This changes the current record in the related tables for the process.

The second form, RELATE ONE(manyField{;choiceField}), looks for the record related to manyField. The relation does not need to be automatic. If it exists, RELATE ONE loads the related record into memory, making it the current record and current selection for its table.

The optional choiceField can be specified only if manyField is an Alpha or Text field. The choiceField must be a field in the related table. The choiceField must be an Alpha, Text, Numeric, Date, Time, or Boolean field; it cannot be a picture or BLOB field.

If choiceField is specified and more than one record is found in the related table, RELATE ONE displays a selection list of records that match the value in manyField. In the list, the left column displays related field values, and the right column displays choiceField values.

More than one record may be found if manyField ends with the wildcard character (@). If there is only one match, the list does not appear. Specifying choiceField is the same as specifying a wildcard choice when establishing the table relation. For information about specifying a wildcard choice, refer to the 4D Design Reference manual.

Example  

Let’s say you have an [Invoice] table related to a [Customers] table with two non-automatic relations. One relation is from [Invoice]Bill to to [Customers]ID, and the other relation is from [Invoice]Ship to to [Customers]ID.

Since both relations are to the same table, [Customers], you cannot obtain the billing and shipment information at the same time. Therefore, displaying both addresses in a form should be performed using variables and calls to RELATE ONE. If the [Customers] fields were displayed instead, data from only one of the relations would be displayed.

The following two methods are the object methods for the [Invoice]Bill to and [Invoice]Ship to fields. They are executed when the fields are entered.

Here is the object method for the [Invoice]Bill to field:

 RELATE ONE([Invoice]Bill to)
 vAddress1:=[Customers]Address
 vCity1:=[Customers]City
 vState1:=[Customers]State
 vZIP1:=[Customers]ZIP

Here is the object method for the [Invoice]Ship to field:

 RELATE ONE([Invoice]Ship to)
 vAddress2:=[Customers]Address
 vCity2:=[Customers]City
 vState2:=[Customers]State
 vZIP2:=[Customers]ZIP

If the command has been executed correctly and if the related records have been loaded, the OK system variable is set to 1. If the user clicked on Cancel in the record selection dialog box (that appears when the related record has been modified), the OK variable is set to 0.

 
PROPERTIES 

Product: 4D
Theme: Relations
Number: 42

The OK variable is changed by the commandThis command changes the currrent recordThe command changes the current selection

 
HISTORY 

Modified: 4D v11 SQL

 
SEE ALSO 

OLD RELATED ONE
RELATE MANY

 
ARTICLE USAGE

4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)