Refactor select_related to support Django semantics and deep caching.