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
This is loop back. You might want to stop the user by saving this record. The dependency will never able to resolve.A after B B after C C after A
There's no logical problem, however your presentation maybe going clumsy. You might want some mechanism for "normalization".Lunch after Breakfast Dinner after Lunch Dinner after Breakfast
In Section
Seekers of Perl Wisdom