Overriding id on create in ActiveRecord

后端 未结 13 2582
自闭症患者
自闭症患者 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条回答
  •  -上瘾入骨i
    2020-11-28 06:06

    You could also use something like this:

    Post.create({:id => 10, :title => 'Test'}, :without_protection => true)
    

    Although as stated in the docs, this will bypass mass-assignment security.

提交回复
热议问题