drawdb-io / drawdb

Free, simple, and intuitive online database diagram editor and SQL generator.
https://drawdb.app
GNU Affero General Public License v3.0
22.71k stars 1.58k forks source link

Cardinality backwards #168

Closed mflagler closed 3 months ago

mflagler commented 4 months ago

Maybe I've always thought of it wrong, but wouldn't the cardinality of one to many indicate that I have 1 record in the table with the primary key to many records in the table with the foreign key? This is currently backwards, and I have to specify this as many to one, which seems backwards to me. Am I the only one thinking this?

1ilit commented 3 months ago

The program doesn't have any 'real' understanding of what the primary and foreign tables are, so the 1 and n labels are assigned first to the 'start table' and then to the 'end table'.

image

For example, here, since postId references posts(id), the relationship gets created from postId to id. Comments becomes the 'start table' and posts becomes the 'end table'. So when you pick many-to-one, the comments side gets n and posts - 1.

At the end of the day, one-to-many and many-to-one are the same thing depending on which table you consider first.

1ilit commented 3 months ago

Feel free to reopen the issue if you still have questions