Hi! I have a legacy table that has a column named "type" and need to remove this automatic subclassing by ActiveRecord. The api pages are vague about this, and I tried self.inheritance_column = "xtype" which seemed to get me half-way. In the validate_on_create method, the value of self.type was my model Class name. How would you disable this feature? -- 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Mar-28 15:51 UTC
Re: Disabling ActiveRecord "type" column subclassing
> Hi! I have a legacy table that has a column named "type" and need to > remove this automatic subclassing by ActiveRecord. The api pages are > vague about this, and I tried > > self.inheritance_column = "xtype" > > which seemed to get me half-way. In the validate_on_create method, the > value of self.type was my model Class name. > > How would you disable this feature?If you want to check ''type'' do self[''type''].. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The short answer is that you can not disable this. The ''type'' method is a Ruby method for the class of an object. As stated by Philip you can access the ''type'' column data by directly indexing the active record. You can also create a facade by having methods on the class that retrieve the ''type'' column using a different name as in: def legacy_type return self[:type] end def legacy_type=(value) self[:type] = value end Michael On Mar 28, 8:34 am, Allen Fair <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi! I have a legacy table that has a column named "type" and need to > remove this automatic subclassing by ActiveRecord. The api pages are > vague about this, and I tried > > self.inheritance_column = "xtype" > > which seemed to get me half-way. In the validate_on_create method, the > value of self.type was my model Class name. > > How would you disable this feature? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
MichaelLatta wrote in post #227241:> The ''type'' method is a Ruby method for the class of an object.This is not a Ruby method. This is part of ActiveRecord, and is used by Rails to manage single-table inheritance. I''m adding a solution for future askers. This applies to Rails 3: class ExampleModel < ActiveRecord::Base set_inheritance_column do ''disabled'' end end This changes the name of the column that ActiveRecord looks for, to use for STI. As long as you pick something that doesn''t actually match any of your column names, it has the effect of disabling inheritance altogether. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Feb 18, 2013, at 7:01 PM, Jaime B. wrote:> MichaelLatta wrote in post #227241: >> The ''type'' method is a Ruby method for the class of an object. > > This is not a Ruby method. This is part of ActiveRecord, and is used by > Rails to manage single-table inheritance.While it is true that ''type'' is not a method in Ruby 1.9, it was in earlier versions: irb1.8.7> 1.type (irb):1: warning: Object#type is deprecated; use Object#class #1.8.7 => Fixnum It is something to keep in mind whenever looking at older code. -Rob> > I''m adding a solution for future askers. This applies to Rails 3: > > class ExampleModel < ActiveRecord::Base > set_inheritance_column do > ''disabled'' > end > end > > > This changes the name of the column that ActiveRecord looks for, to use > for STI. As long as you pick something that doesn''t actually match any > of your column names, it has the effect of disabling inheritance > altogether. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Possibly Parallel Threads
- What i do if i have a table with a column named "type"?
- Serialized object behaves weird
- How do I substitute variables into class names?
- ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'Transactions::DummyDdnlTransaction'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Pleas
- utils::install.packages with quiet=TRUE fails for source packages on Windows