plantuml

How do I create relationship diagram using plantuml with lines touching the exact field


I have successfully created the ERD with standard notations as per the UML with reference to ERD Sample

But I want to make lines exactly touching the field names as specified in this question ERD Or UML

Diagram

is there and inbuilt facility available in plantuml or should I simply alter the x y position of the svg element using CSS ?


Solution

  • In theory it can be done using arrows from/to class members. However, it doesn't work as you'd expect:

    @startuml
    ' hide the spot
    hide circle
    
    ' avoid problems with angled crows feet
    skinparam linetype ortho
    
    entity "Entity01" as e01 {
      * e1_id : number <<generated>>
      __
      * name : text
      description : text
    }
    
    entity "Entity02" as e02 {
      * e2_id : number <<generated>>
      __
      * e1_id : number <<FK>>
      other_details : text
    }
    
    entity "Entity03" as e03 {
      * e3_id : number <<generated>>
      __
      e1_id : number <<FK>>
      other_details : text
    }
    
    e01 ||.left.o{ e02::e1_id
    e01 |o.right.o{ e03::e1_id
    @enduml
    

    relations to class members

    I'd call it a bug in PlantUML, because the lines end in the center of the entity rather than its edge. You could possibly get it fixed by reporting it. However, I doubt you can get a result as nice as the diagram in your question.

    Playing around with up/down and left to right direction gets me a better result:

    @startuml
    ' hide the spot
    hide circle
    
    ' avoid problems with angled crows feet
    skinparam linetype ortho
    
    left to right direction
    
    entity "Entity01" as e01 {
      * e1_id : number <<generated>>
      __
      * name : text
      description : text
    }
    
    entity "Entity02" as e02 {
      * e2_id : number <<generated>>
      __
      * e1_id : number <<FK>>
      other_details : text
    }
    
    entity "Entity03" as e03 {
      * e3_id : number <<generated>>
      __
      e1_id : number <<FK>>
      other_details : text
    }
    
    e01::e1_id ||.up.o{ e02::e1_id
    e01::e1_id |o.down.o{ e03::e1_id
    @enduml
    

    But, again, I doubt this will work with your example. You can try!

    left to right direction hack

    Edit: Looking at this example, you can see that it's pretty close to the example you stated. I think the key is left to right direction.