Fix issues with unregistering nested records.

After upgrading to 1.9, we started having issues with the datastore and nested records. I was able to trace this back to commits 0b5b2db82a and 62d599a85e. I've made some changes here that appear to improve the situation , but I haven't completely fixed the problem and haven't been having much luck finding the problem.

I made a gist (https://gist.github.com/4004203) with a small app that exhibits the problem.

I'd like to get some insight into what might be causing the remaining issues.