laravel/framework — pull request #6551 by bryceray1121 (2014-12-02 21:12:46+00:00)
Title: Eloquent Relationship Query Builder Broken With Global Query Scope

In eloquent when including a sub-model via the eloquent method has (whereHas) 2 queries objects are built and then merged together. The merge is done in an effort to preserve any where statements that a developer may have included prior to calling has. The problem occurs when the subject of the 'has' method (the sub-model) is utilizing a global query scope.
In my example, consider a global query scope which adds several where filters to every query. When the 'has' method generates the 2 query objects each of them have the global query scope and as a result of the whereMerge the resulting query has duplicates of all the where filters. This inconsistency causes several problems including complication of the remove query scope functionality.
My proposed change simply looks at one of the query objects prior to the merge and removes any global scope options that may have been added.

I attempted to write a unit test for this, but i'm unfamiliar with Mockery and it was becoming quite the struggle to represent this scenario. I'm positive it can be done, but may need some assistance on that front.