rtomayko/replicate — pull request #26 by freng (2013-04-03 14:53:34+00:00)
Title: handle cyclic associations

cyclic associations lead to an infinite loop on dump, for instance

```ruby
class Order < ActiveRecord::Base
has_many :states
belongs_to :last_state, :class_name => 'State'
end

class State < ActiveRecord::Base
belongs_to :order
end
```

I suggest two changes which I have implemented as a PoC:

1. on dump: prevent following loops in the object association graph by saving and checking for objects already seen in the traversal
2. on load: when a referenced object is missing, put the referrer on a wait list and reload it when the referee is loaded - otherwise there would be missing foreign keys