Legacy database with column named 'type'

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 W. wrote:

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. :wink:

-Rob

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

2009/7/28 Rob B. [email protected]:

column ‘type’ is reserved for storing the class in case of
the model?
end

(Assuming that there isn’t a column named “not_used” in that table, of
course. :wink:

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 B. wrote:

inheritance.

(Assuming that there isn’t a column named “not_used” in that table, of
course. :wink:


OK, that should work - thanks

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

2009/7/28 Rob B. [email protected]:

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

On Jul 28, 2009, at 12:43 PM, Colin L. wrote:

ActiveRecord::SubclassNotFound: The single-table inheritance

need to change that to something else and then you should be able to

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.

-Rob

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

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.

2009/7/28 Rob B. [email protected]:

column ‘type’ is reserved for storing the class in case of
the model?
end

(Assuming that there isn’t a column named “not_used” in that table, of
course. :wink:

Inheritance_column issues - Rails - Ruby-Forum 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 L. wrote:

failed to locate the subclass: ‘10’. This error is raised because the
in
inheritance_column :not_used
end

(Assuming that there isn’t a column named “not_used” in that table, of
course. :wink:

Inheritance_column issues - Rails - Ruby-Forum 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.