Transaction support for restoring associations

This pull request is mostly a re-implementation of the work done by @tderks and @cambridgemike with some bug fix. I didn't add tests for this pull request. Anyway, I think this solution for has-many association is ready and are already in our company's production mode. And the reason I open this pull request here is want to welcome anybody to help to test it to find if there are still some bugs and if possible add tests for it.