Repository navigation
feat: support cyclic foreign keys - #14499
Merged
Merged
Conversation
ephys
marked this pull request as ready for review
May 12, 2022 08:24
|
Nice, we have exactly this problem! |
WikiRik
previously approved these changes
May 16, 2022
WikiRik
left a comment
Member
There was a problem hiding this comment.
Two comments, but looks good!
Member
|
One test seems to remain broken; @ephys can you check this out? |
Member
Author
|
Yep :) |
WikiRik
approved these changes
May 23, 2022
Member
|
@ephys I'll leave the merging up to you as it will create a new release |
Member
Author
|
Here we go then :) |
Contributor
|
🎉 This PR is included in version 6.20.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
aliatsis
pushed a commit
to creditiq/sequelize
that referenced
this pull request
Jun 2, 2022
3 of 6 tasks
|
With this support do I have to add Reference : Documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
yarn testoryarn test-DIALECTpass with this change (including linting)?Description Of Change
Closes #1717
Note that this PR targets v6, I'll bring it into v7 once merged.
This PR fixes the support for circular foreign key references. (e.g. model A that has a foreign key referencing model B, while B also has a foreign key referencing model A).
This was previously causing
Sequelize#sync,Sequelize#dropandSequelize#truncateto throw because:Sequelize#synctried to create foreign keys before the target table was created. The updated version still does by default, but splits generation in two steps (table creation, then foreign key constraint creation) if there is a cyclic reference.Sequelize#droptried to drop tables that were referenced by other tables. The updated version still does by default but if there is a cyclic reference, it will first remove all foreign keys before dropping all tables.Sequelize#truncatetried to delete rows that were referenced by other tables. This is left unchanged, as the solution is to use thecascadeoption. (for dialects that support CASCADE)TODO