eralchemy icon indicating copy to clipboard operation
eralchemy copied to clipboard

relation cardinality labels drawn in reverse position

Open msladecek opened this issue 6 years ago • 2 comments

Example model:

from sqlalchemy import Column, Integer, String, ForeignKey                                                                                                                                                   
from sqlalchemy.ext.declarative import declarative_base                                                                                                                                                      
from sqlalchemy.orm import relationship                                                                                                                                                                      
                                                                                                                                                                                                             
from eralchemy import render_er                                                                                                                                                                              
                                                                                                                                                                                                             
Base = declarative_base()                                                                                                                                                                                    
                                                                                                                                                                                                             
class Person(Base):                                                                                                                                                                                          
    __tablename__ = 'person'                                                                                                                                                                                 
    name = Column(String(255), primary_key=True)                                                                                                                                                             
    height = Column(Integer)                                                                                                                                                                                 
    weight = Column(Integer)                                                                                                                                                                                 
    birth_location_id = Column(ForeignKey('location.id'))                                                                                                                                                    
    location = relationship('Location')                                                                                                                                                                      
                                                                                                                                                                                                             
class Location(Base):                                                                                                                                                                                        
    __tablename__ = 'location'                                                                                                                                                                               
    id = Column(Integer, primary_key=True)                                                                                                                                                                   
    city = Column(String(255))                                                                                                                                                                               
    state = Column(String(255))                                                                                                                                                                              
    country = Column(String(255))

The way I read the source code:

  • Person has at most one birth location
  • Multiple persons may have the same birth location

Here's the respective diagram generated by eralchemy person-location

The way I read the diagram:

  • 0 to N Locations relate to 0 or 1 Persons

It seems to me that relation representation in the diagram conveys the exact opposite meaning than it should.

Please also note that eralchemy's cardinality label style most closely resembles the UML specification, but label positioning doesn't. This adds another layer of confusion when interpreting eralchemy's diagrams.

relation-styles

Solution proposal: Swap cardinality labels' positions or at least add an option (to CLI and render_er) so that the user can chose for themself.

msladecek avatar Oct 10 '18 16:10 msladecek

Got the same confusion today, indeed the diagram of the example suffers from this issue (see users/comments or users/posts for example)

image

syonekura avatar Oct 12 '18 15:10 syonekura

@Alexis-benoist please, merge PR. It's very desirable fix.

StepanBakshayev avatar Nov 14 '18 13:11 StepanBakshayev