Overriding id on create in ActiveRecord

后端 未结 13 2611
自闭症患者
自闭症患者 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 05:46

    Try

    a_post = Post.new do |p| 
      p.id = 10
      p.title = 'Test'
      p.save
    end
    

    that should give you what you're looking for.

提交回复
热议问题