# Object#type is deprecated; use Object#class

**URL:** <https://www.ruby-forum.com/t/object-type-is-deprecated-use-object-class/117227>\
**Category:** Rails\
**Created:** [October 15, 2007, 2:36am UTC](https://www.ruby-forum.com/t/object-type-is-deprecated-use-object-class/117227 "2007-10-15T02:36:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Virginian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/bc8723/32.png) [@Virginian](https://www.ruby-forum.com/u/Virginian)\
**Post date:** [October 15, 2007, 2:36am UTC](https://www.ruby-forum.com/t/object-type-is-deprecated-use-object-class/117227/1 "2007-10-15T02:36:16Z")

</div>

Thanks in advance for being patient with this rails newbie  
When I do the STI example in AWDWR i get a warning: Object#type is  
deprecated; use Object#class  
What does this mean?  
How should I change the following code?

This is from page 342 AWDWR  
e1/ar/sti.rb  
create\_table :people, :force =\> true do |t|  
t.column :type, :string

Can I change this to

t.column :kind, :string with no ill effects? Or is their something  
special about a column with the name type?  
\*\*  
I read this on [http://api.pluginaweek.org/type\_attributes/](http://api.pluginaweek.org/type_attributes/)

Description  
In Ruby 1.8, type is a deprecated attribute replaced by the class  
method. However, since type is also used in class inheritance within  
ActiveRecord, it will not allow you to access the type attribute as  
defined in a model’s table. Instead, it will return the actual class  
using the deprecated method. This bug fix accesses the actual  
attribute instead if type is defined as a column in the model’s table.  
\*\*  
Should I redefine type as suggested here or is there a better way?

module PluginAWeek #:nodoc:

# Allow +type+ to be accessed as a attribute

module TypeAttributes  
# Retrieves the current value for +type+  
def type  
self.class.column\_names.include?(‘type’) ?  
read\_attribute(:type) : super  
end  
end  
end

ActiveRecord::Base.class\_eval do  
include PluginAWeek::TypeAttributes  
end

---

<div class="post-metadata">

**Author:** ![Virginian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/bc8723/32.png) [@Virginian](https://www.ruby-forum.com/u/Virginian)\
**Post date:** [October 15, 2007, 3:08am UTC](https://www.ruby-forum.com/t/object-type-is-deprecated-use-object-class/117227/2 "2007-10-15T03:08:59Z")

</div>

Change :type to :person\_type. That should solve your problem.

---

<div class="post-metadata">

**Author:** ![Virginian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/bc8723/32.png) [@Virginian](https://www.ruby-forum.com/u/Virginian)\
**Post date:** [October 15, 2007, 3:11am UTC](https://www.ruby-forum.com/t/object-type-is-deprecated-use-object-class/117227/3 "2007-10-15T03:11:19Z")

</div>

Btw, if you change it to person\_type also change the sti id to  
person\_id. You don’t have to use person, you can use anything you want,  
but person seems to fit your schema.
