Fix problem when ordering by dynamic fields