# STI with legacy table

**URL:** <https://www.ruby-forum.com/t/sti-with-legacy-table/173634>\
**Category:** Rails\
**Created:** [August 12, 2009, 11:42am UTC](https://www.ruby-forum.com/t/sti-with-legacy-table/173634 "2009-08-12T11:42:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevtufc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kevtufc](https://www.ruby-forum.com/u/kevtufc)\
**Post date:** [August 12, 2009, 11:42am UTC](https://www.ruby-forum.com/t/sti-with-legacy-table/173634/1 "2009-08-12T11:42:31Z")

</div>

I maintain a rails app which uses a lot of data from a commercial  
system (a student records system) and adds much functionality.

I’m having to make some changes to make the system work with upcoming  
changes to their database and have run into a situation where using  
single table inheritance would be the perfect solution.

The only problem is that the column I need to use stores the object  
type as a single letter instead of a whole class name. Is there a way  
I can use STI with a mapping for type column? So that the string  
stored in the type column is not the class name, but maps 1-to-1 to  
one?

Thanks in advance

Kevin Hughes

---

<div class="post-metadata">

**Author:** ![kevtufc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kevtufc](https://www.ruby-forum.com/u/kevtufc)\
**Post date:** [August 12, 2009, 1:17pm UTC](https://www.ruby-forum.com/t/sti-with-legacy-table/173634/2 "2009-08-12T13:17:55Z")

</div>

I guess you can. Consider this code.

class Category \< ActiveRecord::Base  
end

class Subcategory \< Category  
end

I am inheriting Subcategory from Category. The table’s column ‘type’  
will have values either ‘Category’ or ‘Subcategory’. If I change  
‘Subcategory’ to ‘A’ then my ‘type’ column is going to have ‘Category’  
or ‘A’

for ex.

class A \< Category  
end
