Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

ChildAlias, ChildOrder, OneToMany, ParentAlias, RelationalExpr

These are properties of a relation in the data environment of a form, label or report. They indicate, respectively, the alias and order of the child table in the relation, whether the relation is one-to-many, the alias of the parent table in the relation, and the expression from the parent that controls the relation.

When you drag a field from one table onto a tag of another, a relation is created with the first table’s field for RelationalExpr and the second table’s tag as ChildOrder. ChildAlias and ParentAlias are filled in automatically and can’t be changed.

ChildOrder and RelationalExpr also apply to grids that are the “many” side of a one-to-many setup. If the tables involved have the appropriate relation, you don’t need to set these properties at the grid level. When the tables don’t have the relation, set it up for the grid.

Usage

cChildAlias = frmForm.DataEnvironment.relRelation.ChildAlias
cParentAlias = frmForm.DataEnvironment.relRelation.ParentAlias

These two properties are filled in when you create a relation in the data environment. They cannot be changed in the property sheet or in code. Changing the aliases of the cursors involved automatically changes these properties.

Usage

frmForm.DataEnvironment.relRelation.ChildOrder = cTagname
cTagName = frmForm.DataEnvironment.relRelation.ChildOrder

ChildOrder determines the order of the child table in the relation. ChildOrder supersedes the Order property of the cursor for the child table.

Usage

frmForm.DataEnvironment.relRelation.OneToMany = lIsOneToMany
lIsOneToMany = frmForm.DataEnvironment.relRelation.OneToMany

OneToMany indicates whether the relation is one-to-many. Even when a one-to-many persistent relation is used as the basis for the relation, this property doesn’t get set automatically. You have to set it yourself. At first glance, this may seem odd, but it’s been our experience that we don’t actually use one-to-many relations in our forms that often. Back in 2.x, how frequently did you SET SKIP in a screen? (Reports, of course, are another story.)

Usage

frmForm.DataEnvironment.relRelation.RelationalExpr = cExpr
cExpr = frmForm.DataEnvironment.relRelation.RelationalExpr

RelationalExpr is the expression in the parent table on which the relation is based. In other words, it’s the TO part of the equivalent SET RELATION.

Example

* These properties are normally set in the property sheet
* Assume you've put TasTrade's Customer and Orders tables
* in the Data Environment of a form. To have a one-to-many
* relation between them, properties are set as follows:
ThisForm.DataEnvironment.Relation1.ChildOrder="customer_i"
ThisForm.DataEnvironment.Relation1.RelationalExpr="Customer_id"
ThisForm.DataEnvironment.Relation1.OneToMany=.T.

Although ChildOrder, OneToMany and RelationalExpr can be changed in a running form, the changes you make don’t take effect immediately. You need to CloseTables, then OpenTables. (In fact, it’s better to CloseTables, make your changes, then OpenTables. Otherwise, there’s an ugly information message for each change of this sort you make.)

See Also

LinkMaster, Set Order, Set Relation, Set Skip