增量计数器和导轨“第一”。使用PostgreSQL的奇怪行为 [英] Increment counter and rails "first" using postgreSQL strange behavior
本文介绍了增量计数器和导轨“第一”。使用PostgreSQL的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用增量计数器增加一些整数列并传递一些记录ID,然后尝试使用Model.first获取第一条记录时,这将返回记录ID加1。
When I increment some integer column using increment_counter and passing some record id and then try to get the first record using Model.first, this return the record id plus 1.
是这样的:
Model.increment_counter :field, id
Model.first
它不返回
Model.find(1)
但是
Model.find(id+1)
是
推荐答案
Model.first
将使用数据库的默认排序方式(不一定不一定是ID)。
Model.first
will use the default sorting of your database (which is not necessarily an id).
请尝试以下操作:
Model.order("id").first
这篇关于增量计数器和导轨“第一”。使用PostgreSQL的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文