The logic for matching subdomain.domain.com to domain.com resides in Realm.find_by_url. It should be moved to Domain such that Domain.resolve_from_host_name('subdomain.domain.com') would return domain.com given that there was no subdomain.domain.com registered.