Show/Hide Toolbars

TMS Data Modeler Documentation

Navigation: TMS Aurelius Export > Customization Script

Adding ForeignKey Attribute to Associations

Scroll Prev Top Next More

By default Aurelius defines the name of foreign keys automatically. You can force a name for the foreign key using ForeignKey attribute. Since Data Modeler already holds the name of all foreign keys (relationships) in the database, you can include a ForeignKey attribute to force all foreign keys to have the existing name in database.

 

The following example does that:

 

procedure OnAssociationGenerated(Args: TAssociationGeneratedArgs);
begin
  Args.Field.AddAttribute('ForeignKey').AddRawArgument(      
    '''' + Args.DBRelationship.RelationshipName + '''');              
end;

 

Suppose the original generated source code was this one:

 

    [Association([TAssociationProp.Lazy, TAssociationProp.Required], [])]
    [JoinColumn('ProductID', [TColumnProp.Required], 'ProductID')]    [ForeignKey('FK_Order_Details_Products')]
    FProduct: Proxy<TProduct>;

 

With the script above, it will become this:

 

    [Association([TAssociationProp.Lazy, TAssociationProp.Required], [])]
    [JoinColumn('ProductID', [TColumnProp.Required], 'ProductID')]
    [ForeignKey('FK_Order_Details_Products')]
    FProduct: Proxy<TProduct>;