Sort relations by priority