Object#type is deprecated; use Object#class

As I test my rails application, I’m noticing an increasing amount of the
following warning as I’m testing:

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:74:
warning: Object#type is deprecated; use Object#class

How do I step back and debug this since the warning isn’t in my code?
But, it’s clearly something my code is creating since it does more as I
write more test code.

Could it be because you have a “type” column in your models which
you’re either validating on or accessing? If so, this could help:

http://wiki.pluginaweek.org/Type_attributes

On Sep 28, 4:12 pm, Daniel T. [email protected]

Aaron P. wrote:

Could it be because you have a “type” column in your models which
you’re either validating on or accessing? If so, this could help:

http://wiki.pluginaweek.org/Type_attributes

On Sep 28, 4:12 pm, Daniel T. [email protected]

There’s a few attributes WITH type in the name “question_type”, but none
actually CALLED “type”. Would that still do it? Any other ideas?

Daniel T. wrote:

Aaron P. wrote:

Could it be because you have a “type” column in your models which
you’re either validating on or accessing? If so, this could help:

http://wiki.pluginaweek.org/Type_attributes

On Sep 28, 4:12 pm, Daniel T. [email protected]

There’s a few attributes WITH type in the name “question_type”, but none
actually CALLED “type”. Would that still do it? Any other ideas?

Daniel, did you ever find an answer to this one? I’m getting exactly the
same behavior. I have attributes with “type” in the name, but none
exactly named “type”.

Gabe H. wrote:

Daniel T. wrote:

Aaron P. wrote:

Could it be because you have a “type” column in your models which
you’re either validating on or accessing? If so, this could help:

http://wiki.pluginaweek.org/Type_attributes

On Sep 28, 4:12 pm, Daniel T. [email protected]

There’s a few attributes WITH type in the name “question_type”, but none
actually CALLED “type”. Would that still do it? Any other ideas?

Daniel, did you ever find an answer to this one? I’m getting exactly the
same behavior. I have attributes with “type” in the name, but none
exactly named “type”.

I encountered a similar problem when calling :type on an instance that
(misbehaved and) overrode :type (Mysqlcolumn in this instance). I was
seeing the above error message when I had a nil object and was still
sending type (hence, Object#type handled). The fix was something like:

Before:

find_column(:attribute).type

After:

find_column(:attribute).type if find_column(:attribute)

I have got the same error!

I have used this:

u = User.find 1
u.type
(irb):21: warning: Object#type is deprecated; use Object#class
u.class.name
=> “Admin”

so i have used “u.class.name” instead u.type

Thanks,
Srikanth J

On Sep 25, 2009, at 7:57 AM, Srikanth J. wrote:

so i have used “u.class.name” instead u.type

Thanks,
Srikanth J

http://srikanthjeeva.blogspot.com

If you really have a database column called “type”, then you should be
using Single-Table Inheritance (because ActiveRecord is going to make
that assumption). You can change the column that AR expects to use to
a name different than ‘type’ (look it up) or you can reference
u[‘type’] or u[:type] rather than u.type to avoid the warning.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]