Overriding id on create in ActiveRecord

后端 未结 13 2585
自闭症患者
自闭症患者 2020-11-28 05:07

Is there any way of overriding a model\'s id value on create? Something like:

Post.create(:id => 10, :title => \'Test\')

would be ide

13条回答
  •  清酒与你
    2020-11-28 06:04

    Actually, it turns out that doing the following works:

    p = Post.new(:id => 10, :title => 'Test')
    p.save(false)
    

提交回复
热议问题