11 Mar 2009 @ 1:30 PM 
 

Rails & Legacy Databases

 

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.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • Pownce
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
Tags Tags: , ,
Categories: Rails, Ruby
Posted By: admin
Last Edit: 11 Mar 2009 @ 01 30 PM

E-mailPermalink
 

Responses to this post » (None)

 


Comments are open. Feel free to leave a comment below.


 

Leave A Comment ...

 

 XHTML:
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
\/ More Options ...
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight