Foreman/katello database understanding

Problem: I’m trying to understand foreman/katello database to be able to perform a select that will return me all host that have a repository enabled. I’ve found the following recent commit: Revision d6d9b712 - Fixes #34711 - Search hosts by repository (#10045) - Katello - Foreman
However, I’m still trying to understand which tables/fields are required to join

Expected outcome: Help me understand

Foreman and Proxy versions: I’m actually using Red Hat Satellite 6.10

Foreman and Proxy plugin versions: I’m actually using Red Hat Satellite 6.10

Distribution and version: RHEL 8.5

Other relevant data: