seed_dump
seed_dump copied to clipboard
Topologically sort models to be dumped
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.
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?