0

I am trying to design DB tables with PlantUML class diagrams. But I face a weird behaviour - the order of of fields is not respected. How to show the fields in the original order?

This is a minimum reproducible scenario, the changes are bigger in other classes. PlantUML also draws separator lines randomly.

@startuml
class report_document_types {
    * id: VARCHAR(20)
    * name: VARCHAR(255)
    * is_active: CHAR(1)
    * updated_by: VARCHAR(100)
    * update_ts: DATE
}
@enduml

enter image description here

2
  • 2
    Looks like plantuml sees the fields with the () as methods so probably either use {field} or in stead of () e.g. [] (see also plantuml.com/class-diagram
    – albert
    Commented Apr 18 at 8:09
  • Thanks, that's it. PlantUML really considers that parenthesis as a method. I will accept an asnwer, if you provide it, @albert. Commented Apr 18 at 8:59

1 Answer 1

2

As @albert said in his comment, PlantUML considers elements with () to be methods. Here's what the documentation for PlantUML says:

You can use {field} and {method} modifiers to override default behaviour of the parser about fields and methods.

Applying it to your example gives the expected result:

@startuml
class report_document_types {
    {field}* id: VARCHAR(20)
    {field}* name: VARCHAR(255)
    {field}* is_active: CHAR(1)
    {field}* updated_by: VARCHAR(100)
    * update_ts: DATE
}
@enduml

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.