IDOC: calculate the proper ordering of syncing models, verify that there are no loops

@jamalex we talked about this last night.  This is critical for the new code division that I'm working off of for the IDOC branch.

I tested this by simply printing out the _syncing_models list in every iteration.  Works like a champ!