Fix #10658 - Merge scope if it has a different klass from the current scope

The scope returned from a named scope lambda is associated with the class in which it was defined, which may be an abstract class with no table associcated with it.

This merges the scope into all if its klass is different from the current class ensuring that a scope returned from a named scope is for the class on which the scope was being called.

Fixes #10658