下一个可用的记录 ID [英] next available record id

查看:53
本文介绍了下一个可用的记录 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@user = User.new 

@user.id 返回 nil 但我需要在保存之前知道它.可能吗?

@user.id returns nil but i need to know it before i save. Is it possible ?

推荐答案

不,您无法在保存前获取 ID.ID 号来自数据库,但数据库不会分配 ID,直到您调用 save.当然,所有这些都假设您使用的是 ActiveRecord.

No, you can't get the ID before saving. The ID number comes from the database but the database won't assign the ID until you call save. All this is assuming that you're using ActiveRecord of course.

这篇关于下一个可用的记录 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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