Fetch related records in one go, instead of each one seperately. Also, we sort them properly. Fixes  #2144