轨道:记录没有被标识在Heroku的有序 [英] Rails: Records are not ordered by id in heroku

查看:145
本文介绍了轨道:记录没有被标识在Heroku的有序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林有一个问题,我开发我的应用程序在我当地的环境,一切都会按espected,但在我部署到Heroku的东西是不工作的权利。

Im having a problem I developed my app in my local environment and everything works as espected, but after I deployed to heroku something is not working right.

我有2个型号PurchasingGroup和GroupGoal

I have 2 models PurchasingGroup and GroupGoal

一个采购团有许多组的目标,以及当我创建集团目标为采购团,我可以检查在这样的控制台

a purchasing group has many group goals, well when I create group goals for a purchasing group I can check in the console like this

PurchasingGroup.last.group_goals

和结果是这样的一个

[#<GroupGoal id: 130, created_at: "2015-03-25 17:09:08", updated_at: "2015-03-25 17:10:37", other attributes ommitted>, 
#<GroupGoal id: 131, created_at: "2015-03-25 17:09:08", updated_at: "2015-03-25 17:18:11", other attributtes ommitted]>

嗯,这是正确的,它的工作原理一样,在Heroku和我的地方太多,当一个小组的目标是更新的记录的顺序改变的Heroku(仅在Heroku上),这样的结果是这样的

well this is right, it works like that in heroku and in my local too, when a group goal is updated the order of the records change in heroku (ONLY in heroku) so the result is like this

[#<GroupGoal id: 131, created_at: "2015-03-25 17:09:08", updated_at: "2015-03-25 17:10:37", other attributes ommitted>, 
#<GroupGoal id: 130, created_at: "2015-03-25 17:09:08", updated_at: "2015-03-25 17:18:11", other attributtes ommitted]>

所以如果你看到现在的顺序改变,这打破了很多我的应用程序的功能,所以我必须指定每次像这样

so if you see now the order changed, and this breaks a lot of functionality of my application so I have to specify EVERYTIME like this

PurchasingGroup.last.group_goals.order(:ID)

我必须通过指定的顺序:ID,以使其在Heroku的工作。知道为什么吗?

I have to specify order by :id in order to make it work in heroku. Any idea why?

推荐答案

假设你正在使用Postgres的瓦特/ Heroku的,各种各样的Postgres的通过最近更新的。你必须覆盖默认顺序模型作为的has_many:group_goals,:为了=&GT; ID DESC,或你有什么

Assuming you are using postgres w/Heroku, postgres sorts by the most recently updated. You'll have to override the default order in your model as in has_many: group_goals, :order => "id DESC", or what have you

这篇关于轨道:记录没有被标识在Heroku的有序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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