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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Talsky <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aaron Pfeifer 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 Talsky <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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/ 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Change :type to :person_type. That should solve your problem. Virginian wrote:> 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/ > > 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Virginian wrote:> 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/ > > 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gabe H. wrote:> Daniel Talsky wrote: >> Aaron Pfeifer 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 Talsky <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >> >> 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) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 http://srikanthjeeva.blogspot.com -- Posted via http://www.ruby-forum.com/.
On Sep 25, 2009, at 7:57 AM, Srikanth Jeeva wrote:> 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 > > 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org