Rails 3:“MyModel.all"的默认顺序是什么? [英] Rails 3: What is the default order of "MyModel.all"?

查看:24
本文介绍了Rails 3:“MyModel.all"的默认顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Job.all 返回所有作业的数组.

I know that Job.all returns an array of all jobs.

但是,顺序是什么?

它们是否按 id 升序排列?

Are they ordered by ascending id ?

Job.first 返回什么?文档说:返回找到的第一个资源."

What Job.first returns ? The documentation says: "Returns the first resource found."

但是,查找顺序是什么?

But, what is the looking order ?

推荐答案

默认顺序是 DB 决定返回它们.

The default order is however the DB decided to return them.

查看此处了解更多信息.

See here for more info.

ActiveRecord Find All 未按 ID 排序?

如果您希望它们按特定顺序排列,则应该执行 Model.order()

If you want them in a specific order, you should do Model.order()

这篇关于Rails 3:“MyModel.all"的默认顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆