The relate tag is used to define which fields are used when relating two objects. This tag can be nested in either a hasOne tag or a hasMany tag. This tag has two argments, from and to. The from argument specifies the alias of a field on the parent object (the object in which the hasOne or hasMany tag is nested). The to argument specifies the alias of a filed on the child object.
Note: If a field does not have an alias explicitly set using the field tag then the alias defaults to the field's name.
Multiple relate tags can be nested under a hasOne or hasMany tag to represent compound relationships such as compound foreign keys made up of more than one field.
For detailed information on relationships see the hasOne or hasMany tag documentation.
To understand the relate tag consider a SQL join statement. If you were to join User to Address on an addressId column you would write this SQL code:
SELECT *
FROM User as u JOIN Address as a
ON
u.addressId = a.addressId
<reactor>
<objects>
<object
name="user">
<hasOne
name="address">
<relate
from="addressid" to="addressid" />
</hasOne>
</object>
<object
name="address" />
</objects>
</reactor>
|
Attribute |
Required |
Description |
|---|---|---|
|
from |
yes |
Specifies a field alias on the parent object |
|
to |
Yes |
Specifies a field alias on the child object |
None
<reactor>
<objects>
<object
name="user">
<hasOne
name="address">
<relate
from="addressid" to="addressid" />
</hasOne>
</object>
<object
name="address" />
</objects>
</reactor>