-
Notifications
You must be signed in to change notification settings - Fork 225
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
Topologically sort models to be dumped #102
base: master
Are you sure you want to change the base?
Conversation
My version from a year ago does the same thing. Neither version handles looping dependencies however, where you also need to arrange the records in topological order. I had intended to fix that before offering a PR. |
Yes, that would be nicer. But there's no guarantee that you can do it in any given case, is there? |
It the records got populated in the first place with the constraints as they are, then there's always a solution, i.e. barring a mutual mandatory constraint that requires two records be inserted together. Yes, I have actually done this, on occasion - in a product installation process, using a stored proc that suspended one of the FK constraints - a good way to ensure that the records can't be deleted. |
This is good. Would you still be interested in integrating some tests, @GarthSnyder ? |
Sure, I can do that. |
That's great, thanks ! |
Is there any movement on this? I imagine it's still awaiting tests? |
Any progress? Can we merge this? |
This patch sorts models in dependency order before dumping. This makes seed_dump work correctly with foreign keys and dependencies, including indirect relationships through join tables. (Typically, you must include the :id fields to recreate relationships, of course.) See the original blog post by Ryan Stenberg for a detailed explanation of the logic.
There are currently no tests included, but I will add some if you are interested in integrating this patch.