Toad World® Forums

RoleName from Relation in Case Studio 2

Hi,
I have Case Studio2 and I need change FK name to: FK_ChildAttributeRoleName_ParentAttributeRoleName

All relation is non identifying and between two tables may be more relations.
But I don`t know way to get Child.RoleName when I know Relation.

ParentEntity = Model.GetEntity( Relation.ParentEntityId );
for (i=0; i<ParentEntity.CountAttributes; i++)
{
if (ParentEntity.Attributes(i).PK)
{
Attribute = ParentEntity.Attributes( i );
parentRoleName = Attribute.RoleName;
};
}
I read many ways in TDM byt nothing work in CS2 .

Did anybody know how get it?
Thanks

Hi,

in your example you are trying to get ParentRoleName, but PK attributes do not have RoleName.
RoleName of FK attributes can be found as follows:

ParentEntity = Model.GetEntity( Relation.ChildEntityId );
for (i=0; i<ParentEntity.CountAttributes; i++)
{
if (ParentEntity.Attributes(i).FK)
{
Attribute = ParentEntity.Attributes( i );
if (Attribute.RoleName != ‘’)
childRoleName = Attribute.RoleName;
else
childRoleName = Attribute.ColName;
};
}

Regards,
Lukas

Hi Lukas,

thanks for answer.
For PK I`ll now use Name instead RoleName.
But for FK I have still problem. I have entities where is more FK. How I identify where relation is it?

Hi,

I don’t know if we get it right.
The following query will list FK attributes to the particular relationships.

ChildEntity = Model.GetEntity(Relation.ChildEntityId);
for (i=0; i<ChildEntity.CountAttributes; i++)
{
if (ChildEntity.Attributes(i).FK)
{
Attribute = ChildEntity.Attributes( i );

  for (ii=0; ii<Attribute.AttrFkCount; ii++)
    if (Attribute.RelationFkId(ii) == Relation.Id)
    {
      if (Attribute.RoleName != '')
        childRoleName = Attribute.RoleName;
      else
        childRoleName = Attribute.ColName;
      Log.Writeln(Relation.Name+": "+childRoleName);
    }

};
}

Regards,
Lukas

Now it work, thank you very much Lukas!

Glad to assist you!

Regards,
Lukas & R&D Team