on 07-02-2018 11:47 PM
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!
Thank you so much for this. I would go with the checking and fixing the model.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.