2016-11-08 35 views
0

在我的Rails应用程序中,我有团队和员工,其中的员工是团队成员。两个对象都有序号,我想按升序排序。Rails排序子对象

我该怎么做?我想:

@teams = Team.all.order('"teams"."ordinal" asc, "staffs"."ordinal" asc')

但它没有工作......并给我的错误:

SQLite3::SQLException: no such column: staffs.ordinal: SELECT "teams".* FROM "teams" ORDER BY "teams"."ordinal" asc, "staffs"."ordinal" asc

回答

2

试试这个

Team.includes(:staffs).order('teams.ordinal', 'staffs.ordinal').all 

我不知道怎么样你的关系是由于你没有提供这些信息而设置的。我只给你一个暗示应该怎么做

+0

完美!谢谢。 – Cameron