mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
70.27k stars 6.26k forks source link

ER diagram attributes #1361

Open vwkd opened 4 years ago

vwkd commented 4 years ago

Thanks a ton to @spopida for adding ER diagrams to mermaid in #1308!

As mentioned in the docs, attributes are not yet supported.

ER diagrams are a new feature in Mermaid and are experimental. There are likely to be a few bugs and constraints, and enhancements will be made in due course. Currently you can only define entities and relationships, but not attributes.

It would be awesome if there could be attributes for an entity similar to how classes have members.

Class diagrams unfortunately don't allow to specify relations between their fields. If I understand the distinction correctly, this would be possible with ER diagrams that support attributes.

Attributes for an entity would allow to make diagrams of object models like the following.

er diagram

spopida commented 4 years ago

Hi @zjopy - glad you like the ER diagram feature, and thanks for posting your suggestion. Ability to add attributes is definitely something I would like to do, although I'm not quite sure when! It's my top priority for the next enhancement (if someone doesn't beat me to it!).

Getting the lines to connect to the exact 'correct' place is likely to be challenging, because layout of the diagram is delegated to a rendering engine (dagre), so there is not so much control over where the edges (lines) intersect with the nodes (boxes). But we'll see.

In fact I have a general concern about including foreign keys as attributes, although I know they will be popular and 'everyone does it'. My concern is that the inclusion of a foreign key attribute turns a logical ER model, that could be implemented in various ways, into a physical ER model that follows the relational approach. For example, you can implement a one-to-many relationship in JSON without the need for a foreign key using an array property embedded in the parent entity.

Of course it's not for me to stipulate why people should or shouldn't use physical or logical models, so I think it's perfectly OK to allow foreign key attributes in the diagram. I just want to be careful not to imply that all relationships 'need' foreign key attributes.

Anyway, it's on my radar, and thanks for raising it.

david-morris commented 2 years ago

It looks like attributes without drawing arrows from the correct attribute is currently working, but for some reason there's no documented way to note the multiplicity of an attribute? https://mermaid-js.github.io/mermaid/#/entityRelationshipDiagram At least for the use case of documenting a GraphQL API, being able to write multiplicity is very important.

tritatuy commented 1 year ago

We are also really waiting for ability of making relations between their fields!

jgreywolf commented 1 year ago

@spopida Are you planning on continuing to make any enhancements to ER diagram?

spopida commented 1 year ago

@jgreywolf I'd hate to say 'never' ... but unlikely in the forseeable future due to lack of time

ufukty commented 3 weeks ago

Getting the lines to connect to the exact 'correct' place is likely to be challenging, because layout of the diagram is delegated to a rendering engine (dagre), so there is not so much control over where the edges (lines) intersect with the nodes (boxes). But we'll see.

I'm not sure if this is relevant: another diagraming tool is providing the functionality of drawing relations between exact columns when ELK is used as the engine. So, seems like there is another engine providing the base functionality.