in reply to
Sorting by dependencies
In project management, there's kind of model like this called "Critical Path" which intend to resolve dependency.
Whatever approach you are trying to adopt, you want to consider these 2 situation
A after B
B after C
C after A
This is loop back. You might want to stop the user by saving this record. The dependency will never able to resolve.
Lunch after Breakfast
Dinner after Lunch
Dinner after Breakfast
There's no logical problem, however your presentation maybe going clumsy. You might want some mechanism for "normalization".