ondras / wwwsqldesigner

WWW SQL Designer, your online SQL diagramming tool
https://sql.toad.cz/?keyword=online_library
BSD 3-Clause "New" or "Revised" License
2.87k stars 725 forks source link

Many to many relationship #258

Open amitsharma8891 opened 7 years ago

amitsharma8891 commented 7 years ago

Is there any provision to show many to many relationships?

ondras commented 7 years ago

This tools works on a database level. There are no M:N relationships at this level; if you conceptually need M:N, you must add a third table, converting it to a 1:M + 1:N relationship pair.

So in the end you only want to distinguish 1:1 and 1:N relationships. See this issue for more info.

amitsharma8891 commented 7 years ago

@ondras thanks for your quick response, I definitely explore the suggestions which you have mentioned in this thread.

Also, Can we place some arrow to show the direction of the relationship between the tables?

like: table1 -----------------<- table2

ondras commented 7 years ago

Also, Can we place some arrow to show the direction of the relationship between the tables?

That is basically what the linked issue is all about :-)

amitsharma8891 commented 7 years ago

@ondras thanks for your response, But sorry to say I couldn't find the solution, also there are some broken links in github doc. It would be very helpful if you help me to get the new crowfoot implementation code.

Thanks

ondras commented 7 years ago

Well as far as I know, there is no implementation. The (open) issue discusses what and how shall be implemented, but nobody merged such feature into WWW SQL Designer yet.

amitsharma8891 commented 7 years ago

@ondras if I want to do that, can you assist me from where I can start? also some tips for the same.

Thanks

ondras commented 7 years ago

Rendering these arrows would almost certainly happen in https://github.com/ondras/wwwsqldesigner/blob/master/js/relation.js, in methods redrawNormal and redrawSide. You will want to implement them only in the this.owner.vector branch, as SVG is nowadays supported in all regular web browsers.

The only tricky part is determining the primary/foreign-key part of the relation in order to place the arrow on the proper side. But I suppose this can be solved once you are happy with the rendering itself.

amitsharma8891 commented 7 years ago

@ondras can you give some input to find the direction of relationship?

ondras commented 7 years ago

Well, I have no idea what is the industry standard way of doing that, but a relation line typically connects a primary key field with another which is not a primary key. So this can be used to infer the direction.

But as "deansofer" pointed out in the discussion linked before, indicating the primary key side of the relation using an arrow is kinda pointless, because the arrow would sit literally ten pixels next to the row -- which is already visually distinguished (primary keys are bold).

So in the end it all boils down to what you really expect from the app. Do you have any particular designs/goals in mind, when trying to implement this feature?