我怎么才能取回第二个,第三个..数据库中的条目.我不想使用Rails生成的自动递增id.

随着我从数据库中删除条目,ID也在不断增加.

所以我的数据库会有

id : 210 (Even thought it's currently the first value)
id : 211 (Even thought it's currently the second value)

我知道"Phone.first"会返回第一个,我怎么得到第二个呢?

Sub Question-
Destroy_all/delete_all -
only removes the item, Can I remove all entries from the DB and have the DB id's start from one without dropping the table. As I ran into problems.

推荐答案

假设您想要第四个用户:

 @users = User.limit(4)
 @fourth_user = @users[3]

关于你的第二个问题,destroy_all应该行得通,因为它会触发所有回调.一定要在你们的关系中添加:dependent => :destroy条.

Database相关问答推荐

Postgres和Oracle之间 Select 查询的结果差异

Android SQLiteno such table异常

如何打印出 sequelize 实例的表名?

用于为 Android 设计 SQLite 数据库的开发人员工具

su postgres:Sorry?

如何将新架构添加到现有的 Visual Studio 数据库项目?

sql server:在必要时在外键上创建索引

如何在 VS 2012 的 SQL Server 数据库项目中存储静态数据

使用 PHPUnit 进行数据库测试的最佳实践

设计数据库时最重要的考虑因素是什么?

每个 Docker 容器一个或多个数据库

ORA-00060: deadlock detected while waiting for resource

如何在 MySQL 中强制执行唯一约束?

如何在 Postgres 9.6+ 中生成长度为 N 的随机、唯一的字母数字 ID?

你如何记录你的数据库 struct ?

将一行连接到另一个表中的多行

Django:检测数据库后端

试图在我的环境中设置 Postgres,但似乎无法获得 intidb 的权限

使用 liquibase 更新表中的一行

在具有所需 ForeignKey 引用的 Django (1.8) 应用程序之间移动模型