If you check the code comments above, you can see that this code was intentionally written with raw queries to prevent `Object::__construct` calling `Object::defineMethods`, which would call `Debug::require_developer_login` and thus an infinite loop. This also seems to be the only place where this method is ever called.

```php
// We have to do some raw SQL here, because this method is called in Object::defineMethods().
// This means we have to be careful about what objects we create, as we don't want Object::defineMethods()
// being called again.
// This basically calls Permission::checkMember($_SESSION['loggedInAs'], 'ADMIN');
```

This also leads me to look into https://github.com/silverstripe/silverstripe-framework/issues/1521 to get a working/documented relation filter back into the codebase. That can be another project once this PR is sorted.

For now I'll rewrite the query using a join instead of a subquery, if you are happy for me to proceed this way @simonwelsh. Sorry, I agree with you that filter is the correct way to solve this problem, but the code will need to be refactored more significantly to achieve this, and it may as well be its own pull request.