Introduction 

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.  

TDM_AVBlog1

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. 

 

Application variables 

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 nonidentifying 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: 

  • ChildTableCaption 
  • ChildTableName 
  • ParentTableCaption 
  • ParentTableName 

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. 

TDM_AVBlog2

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) 

TDM_AVBlog3

TDM_AVBlog4

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. 

 

Default values 

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%>%>. 

 TDM_AV5

Picture 4- Default Values 

 

After clicking the "Apply" button, you should get the following message:

 TDM_AVBlog6

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%>”. 

 

Summary 

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.

About the Author

Petr Daricek

Petr Daricek is part of the Quest Software Engineering team, as a Developer Manager for the Toad Data Modeler product. He has extensive experience in developing this product and with relational databases. Petr has worked for Quest for more than 14 years.

Start the discussion at forums.toadworld.com