cancel
Showing results for 
Search instead for 
Did you mean: 

Setting default patterns for identifier & relationship names

costa-b
Explorer
0 Kudos

Hi,

Is there a way to define the default patterns for identifiers (i.e. primary keys) and relationship names?

Right now when I create an entity in a CDM the name of identifiers follow the pattern Identifier_%IncrementalNumber%: Identifier_1, Identifier_2. I want them to be called PK_%EntityCode% (primary identifier), AK%IncrementalNumber%_%EntityCode% for the others.

The same for the relationships. I want to have them set to FK_%ChildEntityCode%_2_%ParentEntityCode%.

Also, if I change the entity name/code I want these to be updated automatically.

Is it doable? Any suggestions?

Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

costa-b
Explorer
0 Kudos

Thank you so much for this. I would go with the checking and fixing the model.

GeorgeMcGeachie
Active Contributor
0 Kudos

You could create "Validate" event handlers on entities and identifiers, but they'd fire up pretty often. Does it really matter that much if your Identifier names don't change if and when the entity code changes? I would use a custom model check on identifiers (with an autofix script) - it would only run when you really need it.

Relationship names are more critical, as they appear in the Browser, so I'd use "initialise" and "validate" event handlers (I wish PD did it out-of-the-box). My event handlers call this function to set relationship names:

Function setRelationshipName(obj)  
' sets the relationship name
dim oldrelname, relname, middlePart 
oldrelname = obj.Name
' set name to the following combination:
' Parent Entity Name -- Parent Role--> Child Entity name
if obj.RelationshipType = "3" then ' many-to-many
  middlePart = " >---< "
else
  if obj.Entity1ToEntity2Role = "" then
  ' parent role not defined, so don't include middle part in relationship name
  ' (it would add a double space, failing one of the other checks)
     middlePart = " ----< "
  else
     middlePart = " -- " & obj.Entity1ToEntity2Role & " --< "
  end if
end if

relname = obj.Entity1.Name & middlePart & obj.Entity2.Name

' if a relationship already exists with this name:  
'  - when creating a new relationship, the PD default name is used  
'  - when updating a relationship, the script will error

if obj.Name = relname then Exit Function
 'if the new name is the same as the old name, exit the function
obj.Name = relname
output Time & " Renamed relationship [" & oldrelname & "] to [" & obj.Name & "]"

End Function

By the way, the CDM has no foreign keys, so I'd avoid confusion, and not use "FK" in relationship names.