Reputation: 6451
I have the following STI models:
class Question < ActiveRecord::Base
class Unapproved < Question
class Approved < Question
If I have a question that is of type Unapproved
, how can I convert it into of type Approved
?
Upvotes: 0
Views: 946
Reputation: 17898
See the becomes
and becomes!
methods, e.g:
Unapproved.first.becomes!(Approved)
Upvotes: 4
Reputation: 5623
I don't think Rails provides a method for autoswitching, but you should be able to do:
Approved.first.update(type: 'Unapproved')
OR
question = Approved.find(x)
question.type = 'Unapproved'
question.save
You could define the autoswitcher yourself in your Question
class too
Upvotes: 1