Rails 4 个 Active Record 顺序在后续方法调用中丢失

Rails 4 Active Record ordering lost on subsequent method calls

当我检索有序的活动记录关系时,对该关系的后续方法调用不会保持顺序。例如:

nodes = post.subtree(:to_depth => 1).order(score: :desc).limit(6)
child_ids = nodes.ids

我希望 child_ids 是一个 ID 数组,其排序方式与节点在 (score/ascending) 中的排序方式相同。不是这种情况。同样,当我打电话给

nodes.arrange 

使用祖先 gem,我得到的不是有序的。它应该如何表现?

试试这个。

nodes = post.subtree(:to_depth => 1).order('score DESC').limit(6)