Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql foreign key multi tenant fix #6828

Merged

Conversation

ronits-cx
Copy link
Contributor

@ronits-cx ronits-cx 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!

@ronits-cx
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!

@ronits-cx ronits-cx 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