Matt Connolly's Blog

my brain dumps here…

Rails: beware a column named ‘type’

It’s been said many times to not use the column name ‘type’, because rails uses this to define the subclass of a model that should be loaded. (great feature, by the way).

But if you have an existing database with a column called “type” and you want to interface to that database with active record, this is a great tip (thanks to this post):

class MyModel < ActiveRecord::Base
  self.inheritance_column = "inheritance_type"
end
Ahh… back to work.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: