cancel
Showing results for 
Search instead for 
Did you mean: 

Add an FK reference using PD scripting

Former Member
0 Kudos

I have the columns defined in the (parent/child) tables.  The parent table has a single column PK.  How do I use PD scripting to add a reference from the child to the parent and to identify one of the existing child table columns to be used in the reference?

Thanks in advance for the help.

View Entire Topic
former_member200945
Contributor
0 Kudos

As far as I can tell there is not document on teaching how to use Powerdesigner API.

Engineering provides some examples in online document. Excel Import Tool you are using is written in vbscript. It contains a lot of information on how to call an API. Some extensions also contain script. Finally Metamodel Objects Help (In PD go to Help) is very useful.

It'll take a while for you get used to the API.

Here is my latest example.

Create a reference between two tables (parent and child). Also using existing column in

child Table(childAddress) as foreign key.

 

set model = ActiveModel
set references = Model.references

set parent= model.findChildByName("parent", cls_Table)
set Pcolumn= parent.findChildByName("parentAddress", cls_Column)

set child = model.findChildByName("child", cls_Table)
set Ccolumn= child.findChildByName("childAddress", cls_Column)

set newRef = references.CreateNew()
newRef.name ="ABC"
newRef.code ="ABC"


set newref.childTable=child
set newref.ParentTable=parent


set Joins=newRef.Joins
for each j in Joins
  set j.ChildTableColumn=cColumn
next

ActiveDiagram.AttachAllObjects

Former Member
0 Kudos

Phillip -- Thanks for the additional sample code.  I read it.  I understood everything.  What I did not get was how one arrives at which API to use and in which order.  I suppose that it goes back to the general question of getting to know the API.