Updating CachedQuery so that it works with NestedRepository correctly.