LearnBoost/mongoose — pull request #1053 by jfremy (2012-08-15 10:19:29+00:00)
Title: remove unsafe use of total in model.js->init

There is an unsafe use of total in the init method (this actually triggered bug for me).
In the poppath.sub code path, if the done callback triggers before you actally execute the final test if(0 === total) test, then next will be executed one time too many and in my case, it screwed up the resulting document.
To fix this, instead of using total, I create a new variable named subobjprocessing (if you want me to change the name, let me know), and I set it to true if I'm populating anything in subobj[key].
The final test (case where nothing was populated) becomes if(!subobjprocessing) instead of if(0 === total).