Upsert in Rails ActiveRecord

后端 未结 1 986
礼貌的吻别
礼貌的吻别 2021-02-11 16:19

Does ActiveRecord have a built-in upsert functionality? I know I could write it myself but I obviously don\'t want to if such a thing already exists.

1条回答
  •  一整个雨季
    2021-02-11 16:45

    Model.find_or_initialize likely does what you want. You can chain it with save or update_attributes if that makes sense.

    More info in the Rails Guides.

    0 讨论(0)
提交回复
热议问题