ActiveRecord: Update a record if exists else create?

后端 未结 7 1733
北荒
北荒 2020-12-30 19:04

Trying to implement an create if not exists else update record in Active Record.

Currently using:

@student = Student.where(:user_id          


        
7条回答
  •  抹茶落季
    2020-12-30 19:54

    It's find_or_create_by not first_or_create.
    Ex: Client.find_or_create_by(first_name: 'Andy')

提交回复
热议问题