Search code examples
ruby-on-railsrubyactiverecordcastingsingle-table-inheritance

How to cast an ActiveRecord object to another class when using STI?


I'm currently using ActiveRecord single table inheritance.

How can I cast one of my models from type A to B? They have the same parent.


Solution

  • #becomes is what you are looking for:

    http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-becomes