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

Topologically sort models to be dumped #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GarthSnyder
Copy link

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.

@cjheath
Copy link

cjheath commented May 17, 2016

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.

@GarthSnyder
Copy link
Author

Yes, that would be nicer. But there's no guarantee that you can do it in any given case, is there?

@cjheath
Copy link

cjheath commented May 17, 2016

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.

@kofronpi
Copy link
Collaborator

kofronpi commented May 9, 2017

This is good. Would you still be interested in integrating some tests, @GarthSnyder ?

@GarthSnyder
Copy link
Author

Sure, I can do that.

@kofronpi
Copy link
Collaborator

That's great, thanks !

@kofronpi kofronpi modified the milestones: 3.3.0, 4.0.0 May 10, 2017
@mvastola
Copy link

mvastola commented Oct 3, 2017

Is there any movement on this? I imagine it's still awaiting tests?

@3minus1
Copy link

3minus1 commented Jul 9, 2018

Any progress? Can we merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants