I have a problem with a table that has a field named ''type'' When I try to use active record in a console, I get this error... ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: ''10''. This error is raised because the column ''type'' is reserved for storing the class in case of inheritance. Please rename this column if you didn''t intend it to be used for storing the inheritance class or overwrite Debtortrans.inheritance_column to use another column for that information. Since I can''t rename the column because the software creating it needs this, is it possible to alias the name somehow within rails, perhaps in the model? Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On Jul 28, 2009, at 11:58 AM, Craig White wrote:> > I have a problem with a table that has a field named ''type'' > > When I try to use active record in a console, I get this error... > > ActiveRecord::SubclassNotFound: The single-table inheritance mechanism > failed to locate the subclass: ''10''. This error is raised because the > column ''type'' is reserved for storing the class in case of > inheritance. > Please rename this column if you didn''t intend it to be used for > storing > the inheritance class or overwrite Debtortrans.inheritance_column to > use > another column for that information. > > Since I can''t rename the column because the software creating it needs > this, is it possible to alias the name somehow within rails, perhaps > in > the model? > > CraigThe default value for the inheritance_column is "type" so you just need to change that to something else and then you should be able to use ''type'' normally for your legacy data. class Debtortrans inheritance_column :not_used end (Assuming that there isn''t a column named "not_used" in that table, of course. ;-) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
2009/7/28 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>:> > On Jul 28, 2009, at 11:58 AM, Craig White wrote: > >> >> I have a problem with a table that has a field named ''type'' >> >> When I try to use active record in a console, I get this error... >> >> ActiveRecord::SubclassNotFound: The single-table inheritance mechanism >> failed to locate the subclass: ''10''. This error is raised because the >> column ''type'' is reserved for storing the class in case of >> inheritance. >> Please rename this column if you didn''t intend it to be used for >> storing >> the inheritance class or overwrite Debtortrans.inheritance_column to >> use >> another column for that information. >> >> Since I can''t rename the column because the software creating it needs >> this, is it possible to alias the name somehow within rails, perhaps >> in >> the model? >> >> Craig > > > The default value for the inheritance_column is "type" so you just > need to change that to something else and then you should be able to > use ''type'' normally for your legacy data. > > class Debtortrans > inheritance_column :not_used > end > > (Assuming that there isn''t a column named "not_used" in that table, of > course. ;-) >Is there another way using some sort of alias on the column name as the OP suggested? I have a legacy db with a column called action and suspect that this may cause me some problems at some point. Maybe it will not however. Colin
On Tue, 2009-07-28 at 12:21 -0400, Rob Biedenharn wrote:> On Jul 28, 2009, at 11:58 AM, Craig White wrote: > > > > > I have a problem with a table that has a field named ''type'' > > > > When I try to use active record in a console, I get this error... > > > > ActiveRecord::SubclassNotFound: The single-table inheritance mechanism > > failed to locate the subclass: ''10''. This error is raised because the > > column ''type'' is reserved for storing the class in case of > > inheritance. > > Please rename this column if you didn''t intend it to be used for > > storing > > the inheritance class or overwrite Debtortrans.inheritance_column to > > use > > another column for that information. > > > > Since I can''t rename the column because the software creating it needs > > this, is it possible to alias the name somehow within rails, perhaps > > in > > the model? > > > > Craig > > > The default value for the inheritance_column is "type" so you just > need to change that to something else and then you should be able to > use ''type'' normally for your legacy data. > > class Debtortrans > inheritance_column :not_used > end > > (Assuming that there isn''t a column named "not_used" in that table, of > course. ;-)---- OK, that should work - thanks Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On Jul 28, 2009, at 12:43 PM, Colin Law wrote:> > 2009/7/28 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>: >> >> On Jul 28, 2009, at 11:58 AM, Craig White wrote: >> >>> >>> I have a problem with a table that has a field named ''type'' >>> >>> When I try to use active record in a console, I get this error... >>> >>> ActiveRecord::SubclassNotFound: The single-table inheritance >>> mechanism >>> failed to locate the subclass: ''10''. This error is raised because >>> the >>> column ''type'' is reserved for storing the class in case of >>> inheritance. >>> Please rename this column if you didn''t intend it to be used for >>> storing >>> the inheritance class or overwrite Debtortrans.inheritance_column to >>> use >>> another column for that information. >>> >>> Since I can''t rename the column because the software creating it >>> needs >>> this, is it possible to alias the name somehow within rails, perhaps >>> in >>> the model? >>> >>> Craig >> >> >> The default value for the inheritance_column is "type" so you just >> need to change that to something else and then you should be able to >> use ''type'' normally for your legacy data. >> >> class Debtortrans >> inheritance_column :not_used >> end >> >> (Assuming that there isn''t a column named "not_used" in that table, >> of >> course. ;-) >> > > Is there another way using some sort of alias on the column name as > the OP suggested? I have a legacy db with a column called action and > suspect that this may cause me some problems at some point. Maybe it > will not however. > > ColinIf it''s because you see "action" in this page: http://wiki.rubyonrails.org/rails/pages/ReservedWords (or a similar one), then it is probably within a controller. You shouldn''t have problems with ''action'' as a column/attribute name on a model. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
2009/7/28 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>:> > > On Jul 28, 2009, at 12:43 PM, Colin Law wrote: > >> Is there another way using some sort of alias on the column name as >> the OP suggested? I have a legacy db with a column called action and >> suspect that this may cause me some problems at some point. Maybe it >> will not however. >> >> Colin > > If it''s because you see "action" in this page: > > http://wiki.rubyonrails.org/rails/pages/ReservedWords > > (or a similar one), then it is probably within a controller. You > shouldn''t have problems with ''action'' as a column/attribute name on a > model. >I admit I have not run into a problem yet, I suppose I am concerned that something like :conditions => {:action => value} might confuse the system. I suppose if it did I could avoid the use of :action by using [''action = ?'', value] instead. I will not worry unless it becomes a problem. Thanks for the help. Colin
I had a similar problem when I hooked my Wordpress installation into my rails site. On the wp_posts table they use ID as their primary key. Ruby/Rails was getting unhappy whenever I tried to access obj.ID. I was able to access this field by using obj.attributes ["ID"]. I don''t know if this will work for you without a code example, but its worth a shot. On Jul 28, 10:58 am, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> I have a problem with a table that has a field named ''type'' > > When I try to use active record in a console, I get this error... > > ActiveRecord::SubclassNotFound: The single-table inheritance mechanism > failed to locate the subclass: ''10''. This error is raised because the > column ''type'' is reserved for storing the class in case of inheritance. > Please rename this column if you didn''t intend it to be used for storing > the inheritance class or overwrite Debtortrans.inheritance_column to use > another column for that information. > > Since I can''t rename the column because the software creating it needs > this, is it possible to alias the name somehow within rails, perhaps in > the model? > > Craig > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean.
2009/7/28 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>:> > On Jul 28, 2009, at 11:58 AM, Craig White wrote: > >> >> I have a problem with a table that has a field named ''type'' >> >> When I try to use active record in a console, I get this error... >> >> ActiveRecord::SubclassNotFound: The single-table inheritance mechanism >> failed to locate the subclass: ''10''. This error is raised because the >> column ''type'' is reserved for storing the class in case of >> inheritance. >> Please rename this column if you didn''t intend it to be used for >> storing >> the inheritance class or overwrite Debtortrans.inheritance_column to >> use >> another column for that information. >> >> Since I can''t rename the column because the software creating it needs >> this, is it possible to alias the name somehow within rails, perhaps >> in >> the model? >> >> Craig > > > The default value for the inheritance_column is "type" so you just > need to change that to something else and then you should be able to > use ''type'' normally for your legacy data. > > class Debtortrans > inheritance_column :not_used > end > > (Assuming that there isn''t a column named "not_used" in that table, of > course. ;-) >http://www.ruby-forum.com/topic/101557 suggests that just changing the inheritance column name may not be enough, it may also be necessary to provide access methods as type is a reserved word. The link suggests a solution. Colin
On Tue, 2009-07-28 at 21:31 +0100, Colin Law wrote:> 2009/7/28 Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>: > > > > On Jul 28, 2009, at 11:58 AM, Craig White wrote: > > > >> > >> I have a problem with a table that has a field named ''type'' > >> > >> When I try to use active record in a console, I get this error... > >> > >> ActiveRecord::SubclassNotFound: The single-table inheritance mechanism > >> failed to locate the subclass: ''10''. This error is raised because the > >> column ''type'' is reserved for storing the class in case of > >> inheritance. > >> Please rename this column if you didn''t intend it to be used for > >> storing > >> the inheritance class or overwrite Debtortrans.inheritance_column to > >> use > >> another column for that information. > >> > >> Since I can''t rename the column because the software creating it needs > >> this, is it possible to alias the name somehow within rails, perhaps > >> in > >> the model? > >> > >> Craig > > > > > > The default value for the inheritance_column is "type" so you just > > need to change that to something else and then you should be able to > > use ''type'' normally for your legacy data. > > > > class Debtortrans > > inheritance_column :not_used > > end > > > > (Assuming that there isn''t a column named "not_used" in that table, of > > course. ;-) > > > > http://www.ruby-forum.com/topic/101557 suggests that just changing the > inheritance column name may not be enough, it may also be necessary to > provide access methods as type is a reserved word. The link suggests > a solution.---- my own experience suggests that this was the solution that worked for me...that simply changing the inheritance_column was not enough. Thanks Rob & Colin Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.