I reversed engineered a database and it is displaying the caption “FK_[parent table name]to[child_table_name]”. I would like the caption to display "[parent table name]:[column name]-[child table name]:[column name].
Is there any way I can do this without manually editing all the captions?
Thank you
Hello there,
The fastest way is to use a macro, please try executing the one I enclosed in Expert Mode Menu | Scripting Window (you need to enable Expert Mode in Settings Menu | Options | General). It should rename all of your FKs in the model according to the pattern you mentioned.
Regards,
Lukas
RenameForeignKeys.txt (1.26 KB)
Thank you for the script. It was very valuable.
The script changed the caption but inside the entity. I used it as a reference to change the relation caption. I’m including the modified script that worked for me but my database foreign keys only have one column for each table. I don’t think my script would work otherwise.
function main() {
var x, y, iterRel, childEntityName, parentEntityName, newCaption;
for (x = 0; x < Model.Relations.Count; x++) {
iterRel = Model.Relations.GetObject(x);
childEntityName = iterRel.ChildEntity.name;
parentEntityName = iterRel.ParentEntity.name;
for (y = 0; y < iterRel.ForeignKeys.Count; y++) {
foreignKey = iterRel.ForeignKeys.GetObject(y);
newCaption = "[" + parentEntityName + "-" + foreignKey.AttrParent.name + "]" + ":" + "[" + childEntityName + "-" + foreignKey.AttrChild.name + "]";
//Log.Information(newCaption);
}
iterRel.caption = newCaption;
}
Model.RefreshModel();
}