Changing type of ActiveRecord Class in Rails with Single Table Inheritance

Steve’s answer works but since the instance is of class BaseUser when save is called, validations and callbacks defined in User will not run. You’ll probably want to convert the instance using the becomes method:

user = BaseUser.where(email: "[email protected]").first_or_initialize
user = user.becomes(User) # convert to instance from BaseUser to User
user.type = "User"
user.save!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)