我有两个模型:
class Country
has_many :competitions
end
class Competition
belongs_to :country
end
比赛类有一个位置属性。管理员可以按位置对比赛进行排序。我想对竞争中排名最低的国家进行排序。我也想参加与国家的比赛。我怎样才能做到这一点?
我想要一个像这样的输出:
X Country: (is at first order because Xcomp1's position is 1)
Xcomp1 (position: 1)
Xcomp2 (position: 12)
A Country:
Acomp1 (position:2)
Acomp2 (position:3)
Z Country: (is at last position because minimum position of its competitions are higher than other ones)
Zcomp1 (position:5)