Skip to content

Relations and Constraints

Relations and constraints explain how entity relationships, related Data Dictionary objects, and runtime filters work together.

Define relationships on entities

Define persistent relationships on the entity with Add_Relation:

Add_Relation CustomerId to Customer.Id

Multi-segment relations continue with and ;:

Add_Relation OrderId to OrderHeader.Id and ;
             LineNo to OrderHeader.LineNo

Entity relations describe how a child entity points at a parent entity. See Entities for entity metadata, fields, indexes, and relation syntax.

A child Data Dictionary connects to parent Data Dictionary objects with Set DDO_Server:

Object oCustomerDD is a cCustomerDataDictionary
End_Object

Object oOrderHeaderDD is a cOrderHeaderDataDictionary
    Set DDO_Server to oCustomerDD
End_Object

The entity relation must exist before a child Data Dictionary can use the parent as a server. See Data Dictionaries and Relate for related DD behavior and command-style porting notes.

Limit child rows with constraints

Constrain_File limits a child Data Dictionary to rows related to the active parent record:

Set Constrain_File of oOrderDetailDD to (RefTable(oOrderHeaderDD))
Send RebuildConstraints of oOrderDetailDD

Reusable constraints belong in OnConstrain:

Procedure OnConstrain
    Constrain Self.Name contains "Corp"
End_Procedure

Constraints affect rows visible to the Data Dictionary local buffer.

Command-style constraints

Command-style constraints map to Data Dictionary constraint APIs:

Constrain oCustomerDD.Balance GT 30000
Constrain oInventoryDD Relates to oVendorDD
Constrain oOrderDD.OrderDate Between dStart and dEnd

See Constrain for command syntax and its Data Dictionary equivalents.

API reference shortcuts

Checklist

  1. Define Add_Relation on the entity.
  2. Instantiate parent DDs before children that reference them.
  3. Set DDO_Server on child DDs.
  4. Set Constrain_File only when child rows should follow an active parent.
  5. Rebuild constraints after changing reusable constraint inputs.
  6. Remove standalone Relate command calls when porting.