Skip to content

Fix incorrect foreign key assignment direction on dragging#884

Open
Jadu07 wants to merge 2 commits intodrawdb-io:mainfrom
Jadu07:fix/foreign-key-assignment-clean
Open

Fix incorrect foreign key assignment direction on dragging#884
Jadu07 wants to merge 2 commits intodrawdb-io:mainfrom
Jadu07:fix/foreign-key-assignment-clean

Conversation

@Jadu07
Copy link
Contributor

@Jadu07 Jadu07 commented Feb 28, 2026

fixes #873

This pull request fixes an issue with how table relationships were created using drag and drop. Earlier, when dragging from a parent table (Primary Key) to a child table (Foreign Key), the generated SQL added the foreign key to the wrong table. Even though the connection looked correct in the UI, the SQL logic behind it was reversed.

The problem was that the system always treated the table where the drag started as the child table. Because of this, the foreign key was assigned to the parent table when users dragged from parent to child.

To fix this, changes were made in src/components/EditorCanvas/Canvas.jsx inside the handleLinking() function. The logic for assigning startTableId and endTableId was updated so that the child table (the Foreign Key holder) is always set as startTableId, and the parent table (the Primary Key holder) is set as endTableId.

With this change, dragging from a Primary Key table to a Foreign Key table now generates correct SQL syntax, where the foreign key is added to the child table as expected. Below are screenshots showing the behavior before and after the fix when running the project locally.

Before (Incorrect SQL syntax):

Screenshot 2026-03-01 at 1 50 08 AM Screenshot 2026-03-01 at 2 04 18 AM

After (Correct SQL syntax running locally):

Screenshot 2026-03-01 at 2 13 02 AM Screenshot 2026-03-01 at 2 13 33 AM

@vercel
Copy link

vercel bot commented Feb 28, 2026

@Jadu07 is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Jadu07
Copy link
Contributor Author

Jadu07 commented Mar 3, 2026

@1ilit pls review this pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SQL Export inverts Foreign Key cardinality (Visual vs SQL mismatch)

1 participant