I agree that supporting foreign keys requires some topological sorting of the Table instances. How does the _ordinal field in the Record class help? Maybe it's better if you push the whole story.