Skip to Content

Setting default patterns for identifier & relationship names


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?


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jul 04, 2018 at 09:41 AM

    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 = " >---< "
      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 = " ----< "
         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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 04, 2018 at 07:08 PM

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

    Add comment
    10|10000 characters needed characters exceeded