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.
Connect related Data Dictionaries¶
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¶
DDO_ServerDefineRelationConstrain_FileAdd_Value_ConstraintAdd_Field_Value_ConstraintAdd_Relates_To_ConstraintRebuildConstraintsRebuildAllConstraintsOnConstrainCascadeDeleteAllowedCascadeDeleteNullParentNullAllowedParentNoSwitchIfCommittedAllowParentFind
Checklist¶
- Define
Add_Relationon the entity. - Instantiate parent DDs before children that reference them.
- Set
DDO_Serveron child DDs. - Set
Constrain_Fileonly when child rows should follow an active parent. - Rebuild constraints after changing reusable constraint inputs.
- Remove standalone
Relatecommand calls when porting.