



There are a number of gotchas when using rails with legacy db’s. Here are the ones I’ve ran headfirst into and how I got round them
Table name doesn’t follow rails naming conventions:
set_table_name ‘legacy_name’
Primary key doesn’t follow rails naming conventions:
set_primary_key ‘legacy_primary_key_name’
Using a sequence (need to do this in oracle):
set_sequence_name ‘legacy_sequence_name’
So far so straightforward, you might however also run into problems with some field names.
Table.type:
set_inheritance_column ‘not_type’
ActiveRecord inheritance works automagically comes into play if you have a column named type, by setting it to not type it won’t try to use pixiedust on your model.
Table.class:
class << self
def instance_method_already_implemented?(method_name)
return true if method_name == ‘class’
super
end
end
def pclass=(text)
self[:class] = text
end
def pclass
self[:class]
end
You might find some of your field names clashing with some basic ruby / rails keywords the first section will prevent your field being hidden and the pclass attr allows you to rename the field name in your model.
If I come across any other I’ll update this list but it’s handy stuff to know.










More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS

Void (Default)
Life
Earth
Wind
Water
Fire
Lightweight