最佳答案
这样做会覆盖数据库排序:
@item.children.except(:order).order("your_sort_column")
例子:
organization.self_and_descendants.to_sql
=> "SELECT `organizations`.* FROM `organizations` WHERE (`organizations`.`lft` >= 1 AND `organizations`.`lft` < 54) ORDER BY `organizations`.`lft`"
organization.self_and_descendants.except(:order).order("organization_nm").to_sql
=> "SELECT `organizations`.* FROM `organizations` WHERE (`organizations`.`lft` >= 1 AND `organizations`.`lft` < 54) ORDER BY organization_nm"
关于ruby-on-rails - 很棒的嵌套设置顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1347885/