Fixed wrong field caches resulting in missing lookup keys in various cases

We cannot call get_related_field() during class compilation time. This
builds up internal caches too early and therefore incomplete.