在我的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
试试这个
Team.includes(:staffs).order('teams.ordinal', 'staffs.ordinal').all
我不确定你的关系是如何建立的,因为你没有提供这些信息。我只是给你一个应该怎么做的提示