Book a Demo

Author Topic: Creating table PKs with Javascript  (Read 3777 times)

davidn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Creating table PKs with Javascript
« on: December 08, 2018, 03:21:31 am »
Hey,

I'm wondering how to create primary keys on tables with Javascript. I have a table and know which Attribute (var attr) I want to set the Primary Key as. However, the following code is not updating the Attribute to a PK:

Code: [Select]
attr.IsOrdered = true;
attr.Update();
theElement.Update();

theElement has Stereotype table and Gentype MySql.

Going into EA and then manually ticking the PK box on attr updates it to a PK.

Any insight? Thanks!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Creating table PKs with Javascript
« Reply #2 on: December 10, 2018, 06:29:30 pm »
If the JavaScript is becoming too much effort then an alternative path to get a quick result of  adding PK and FK might be to do a DDL transformation. However that adds new attributes.
Happy to help
:)

davidn

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Creating table PKs with Javascript
« Reply #3 on: December 11, 2018, 03:27:38 am »
Thanks, guys.

Sunshine, how can I do the DDL transform you mentioned?

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Creating table PKs with Javascript
« Reply #4 on: December 11, 2018, 07:08:37 pm »
To do transform select package and from ribbon Design > Tools > Transform > Transform Selection
Apply Transform
Select classes
Select DDL Transform
Click Do Transform button
For detailed description see
https://sparxsystems.com/resources/user-guides/14.0/model-domains/model-transformation.pdf
Try the search its wonderful at finding things :)
Happy to help
:)