Toad World® Forums

How to prepend inherited PK field names using Super/Subtype names when generating Physical from Logical model


#1

Hi modeling friends:

I want the Logical to Physical conversion process to construct new PK names by prepending subtype table names to the inherited PK fields.

I have a logical model that implements (part of) the Party/Role pattern (see http://tdan.com/a-universal-person-and-organization-data-model/5014 for example).

Party is identified by PartyID.

I have two specialized Parties - Offerer and Receiver - using an inheritance model that when converted using the “N Tables - Physical Model Matches Logical model” I get this:

PARTY: PartyID

OFFERER: PartyID (PFK), PartyType (= “OffererType” - FK to PartyType)

RECEIVER: PartyID (PFK), PartyType (=“ReceiverType” - FK to PartyType)

Now when The Offerer makes an offering and the Receiver chooses that offering, I store this in a Fulfillment table:

FULFILLMENT: PartyID* (Offerer), PartyID* (Receiver),

  • Note the same attribute names - this is undesirable in the Physical Model.

When I convert the Logical model to a Physical model I want the inherited PKs to become like this:

PARTY: PartyID

OFFERER: OffererPartyID (PFK), TypeCode (= “Offerer” - FK from table PartyType)

RECEIVER: ReceiverPartyID (PFK), TypeCode (=“Receiver” - FK from table PartyType)

FULFILLMENT: OffererPartyID (PFK), ReceiverPartyID (PFK), DateTime (PK)

PARTYTYPE: TypeCode (PK)

Are there any defaults I can modify to make the subtype Primary Keys generate automatically using the subtype table name - eg “OffererPartyID” , and have that name then inherited by the dependent table (Fulfillment)?

Also, I want the Discriminator (ie “TypeCode” in my Logical model) to default to the subtype Table name (eg “Offerer”) - can I do that automatically when converting from Logical to Physical?

Thanks.

Greg


#2

Hello Greg,

I think you mean logical model like this

LM.png

When you convert it to Physical (for example Oracle 10g) you get

PM1.png

In Main Menu - Settings - Options - Physical Model are fields “Relation Attribute Name” and “Relation attribute Caption”. You can change rule for default name of migrated attribute by relation. This rule is use for conversion from Logical to Physical model too. You can change Relation Attribute Name to “<%OwnerName%><%ParentAttributeName%>” and all migrated attribute will have prefix of table, but it will be valid for all migrated attribute. So our example will be:

PM2.png

Background:

To default “Relation Attribute Name” you can insert any text or some of predefined Application Variables for attribute( <%Application_Variable%>). You can see list of predefined application variables on Attribute properties dialog when click on button “<%>”. As application variable you can use any string property. So you can create by metamodel your new string property and define it’s value by script, if you have any good criterion.

Daril


#3

Most excellent, thanks Daril - that’s exactly what I want to achieve.

(This feature is particularly appreciated when doing complex super/subtype models)

All the best

Greg