Skip to content

Mysql foreign key multi tenant fix#6828

Merged
imnotjames merged 31 commits intotypeorm:masterfrom
checkmarx-ltd:mysql-foreign-key-multi-tenant-fix
Oct 4, 2020
Merged

Mysql foreign key multi tenant fix#6828
imnotjames merged 31 commits intotypeorm:masterfrom
checkmarx-ltd:mysql-foreign-key-multi-tenant-fix

Conversation

@cx-ronit-steinberg
Copy link
Contributor

@cx-ronit-steinberg cx-ronit-steinberg commented Oct 2, 2020

This change will fix issue 6168, where the foreign key queried might be wrong.
There is already another open PR for this issue: PR 6169.
The difference is that this PR is a split from another pending performance fix, which needs the condition to be where it is here in order to later add the performance fix.

The foreign key query has a JOIN and a where clause on the schema and table names, but the where clause is only for one of the tables in the join. This way in a multi-tenanted environment, it's possible for several schemas to have the same foreign key name, resulting in duplicate results in the query.

@imnotjames imnotjames self-requested a review October 2, 2020 17:56
Copy link
Contributor

@imnotjames imnotjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments :)

Copy link
Contributor

@imnotjames imnotjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏

Just waiting on tests to pass!

@cx-ronit-steinberg
Copy link
Contributor Author

Awesome thanks! 😄

@imnotjames imnotjames merged commit c060f95 into typeorm:master Oct 4, 2020
@imnotjames
Copy link
Contributor

Wonderful. Thank you for the contribution!

@cx-ronit-steinberg cx-ronit-steinberg deleted the mysql-foreign-key-multi-tenant-fix branch October 4, 2020 07:31
@imnotjames imnotjames added the hacktoberfest-accepted label hacktoberfest label Oct 7, 2020
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
Fixes an edge case where the wrong foreign key 
would be loaded when multiple databases exist 
with foreign keys that have the same name.

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

Labels

hacktoberfest-accepted label hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong foreign key information loaded from schema

3 participants