May 15, 2019 3:32:22 PM by Petr Daricek
Toad Data Modeler by default sets the name for relationships to "RelationshipX", where X is the unique number in the model. This behavior guarantees that all relationships will have a unique name, but is not very useful.
Picture 1 – Default State in Toad Data Modeler
There is a way to improve this behavior using the key features Application Variables and Default Values. Both topics you can find in the Toad Data Modeler help. In this article I want to show you how to derive the relationship name from parent and child entities.
You can start by creating a simple model with two Entities and one relationship as shown on Picture 1 above. We can name the parent entity “ParentEntity” and the child entity “ChildEntity”. Because caption “ParentEntity” is not very useful, you can change the caption to “Parent Entity”. So only insert the space between words. Similarly, you can update the caption for the child entity.
Now, create an identifying relationship (which works the same for non-identifying relationships) from ParentEntity to ChildEntity.
Double Click on Relationship1 to open the Relationship Properties dialog. Next, click on the button in the bottom left corner to show the “Application Variables” window. This window is a very useful tool to work with Application Variables. At first you can see in this window the available Application Variables that you can use for objects in the property dialog. Lower in the window you can see which properties you can use. And last, but not least you can insert appropriate Application Variables by double click.
For our example, these are interesting application variables:
In order to make changes, first clear the Caption field of relationship and leave your cursor in Caption edit. Now double click on ParentTableCaption in the Application Variables window. It inserts into edit text "<%ParentTableCaption%>“. By a similar process insert into Caption text "Relation <%ParentTableCaption%> <%ChildTableCaption%>“ and into Name text "REL_<%ParentTableName%>_<%ChildTableName%>“. All variables within "<%“ "%>“ are application variables, outside is normal text. Now click the "Apply" button and you can see what you will see on designer.
Picture 2- Settings of Relationship Properties
On designer you can see REL_ParentEntity_ChildEntity or Relation Parent Entity Child Entity (Depending if you have Caption or Name mode on in designer)
Picture 3 – Evaluated Names on Designer
Now when you change the name of the parent or child entity, the relationship name is automatically changed too. If an old name is preserved in designer, it may be necessary to refresh it by using the command "Refresh Application Variables“ from the designer popup menu or using model in model explorer.
Now you can call relationships by variables. This relationship name will automatically be changed and you don’t have to remember to change it separately.
From previous section we know how to use application variables in a relationship name. But, the Default Name is still in the form “RelationshipX”. It can be useful to have the default name in the form “REL_<%ParentTableName%>_<%ChildTableName%>” (Similar to Caption).
In order to change default values, first you need to switch to Expert mode (because Toad Data Modeler considers you to be an expert when you do this).
After switching to Expert mode, Open the Relationship dialog, right click on it and choose item “Default Values for Class”. Find the "Name" Default Value (should be empty) and edit it by F2 and insert into the value the text “REL_<%<%ParentTableName%>%>_<%<%ChildTableName%>%>”.
Picture 4- Default Values
After clicking the "Apply" button, you should get the following message:
Picture 5 – Restart Message
Click on the "Yes" button to restart Toad Data Modeler.
Now when you create a new relationship, it will be named in the form “REL_<%ParentTableName%>_<%ChildTableName%>”.
When you use default values application variables in the form “<%APP_VAR%>” it will be evaluated when an object is created. When you use the form “<%<%APP_VAR%>%>”, the application variable will be inserted into the appropriate property.
Only some application variables make sense to evaluate when creating an object. This is because the majority of properties are set after the object is created. It makes sense to evaluate Application Variables such as Date, Time, Author.
You can find more information on Toad Data Modeler, including additional information on Application Variables in the Toad Data Modeler User's Guide.
Tags: Toad Data Modeler
Written by Petr Daricek
Petr Daricek is part of the Quest Software Engineering team, and helps develop Toad products including Toad Data Modeler.