rails/rails — pull request #12472 by arthurnn (2013-10-09 00:50:31+00:00)
Title: track the saving state so before callbacks dont loop

### Problem
`stack level too deep`
This is because the `belongs_to` reference auto saves the parent,(when the parent is set) and when having a `inverse_of` relation, the child will set the parent in memory, which on the `save_belongs_to_association` callback will try to save the parent again. So we would loop in the before_callbacks.

### Solution
We track the saving state, so inside the `save_belongs_to_association` we only save the parent if it isn't in saving state.

review @tenderlove @rafaelfranca

If you guys like this solution I can patch this to rails 4/master too.