Fix for issue #6116.

Fix for issue #6116.
Currently using and advanced where inside a GlobalScope apply() method creates an enless loop beause of the `->applyGlobalScopes()->removeGlobalScopes()` produced with `newQueryWithoutScopes()`.

I've moved some code to prevent this. Nothing new is added, just made sure of calling `->applyGlobalScopes()` only when needed...