Read my latest article: 8 things I look for in a Ruby on Rails app (posted Thu, 06 Jul 2017 16:59:00 GMT)

Sneaking Rails through the (Legacy) system

Posted by Fri, 14 Apr 2006 22:01:00 GMT

3 comments Latest by Fabio Akita Thu, 29 Jun 2006 20:06:36 GMT

I’ll be posting stuff in the next few days about acts_as_legacy. For those not at Canada on Rails... I announced a small project that I’m going to be working on.

Acts as Legacy!

Here are my slides… up til I tried to do a live demo. ;-)

# Inventory model
class Inventory < ActiveRecord::Base
  acts_as_legacy :table_name => 'inventory',
                 :primary_key => 'prod_id',

  has_one :product, :foreign_key => self.primary_key

  column_alias :quan_in_stock, :stock

Let’s try something a little different…

# SalesPerson model
class SalesPerson < ActiveRecord::Base
  acts_as_legacy :table_name => 'sales_person',
                 :primary_key 'sales_p_id',
                 :column_alias => 'sales_p_'

  validates_presence_of( :name, :email, :phone ) 

# usage....
SalesPerson.find( 7 ).sales_p_name
=> 'Nigel'
SalesPerson.find( 7 ).name
=> 'Nigel'

The Slideshow

...Jeremy posted his slides as well. :-)

Get help with your Rails project

comments powered by Disqus

Leave a response

  1. Avatar
    Rob Sanheim Thu, 20 Apr 2006 15:56:08 GMT

    Hey Robby,

    Is the code for this available anywhere?

  2. Avatar
    Rob Goodwin Sun, 30 Apr 2006 17:37:12 GMT

    has commenting been fixed yet?

  3. Avatar
    Fabio Akita Thu, 29 Jun 2006 20:06:36 GMT

    I have nothing against the Surrogate Key-only for Active Record but do you intend to support intelligent keys (as the username in a User model) or even composite primary keys? Many people seems to miss those.