Rails AR 中 新建一个实例时,怎么给他一个默认 id?

lmorenbit · November 12, 2012 · Last by lmorenbit replied at November 12, 2012 · 2198 hits

请教 post = Post.new :title => "This is title" => #<Post :id => number, :title => "This is title">

如果是在 mysql 中,是主键要唯一,可以不连续

如果使用 Post.create() 即可带上id, 这时注意的就是它已经被存入数据库了。

You need to Sign in before reply, if you don't have an account, please Sign up first.