Read my latest article: Ezra Zygmuntowicz -- Farewell, Friend. (posted Mon, 01 Dec 2014 17:53:00 GMT)

Sneaking Rails through the (Legacy) system

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

3 comments Latest by Fabio Akita Thu, 29 Jun 2006 21: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

end   
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 ) 
end

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

The Slideshow

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

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
comments powered by Disqus
Comments

Leave a response

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

    Hey Robby,

    Is the code for this available anywhere?

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

    has commenting been fixed yet?

  3. Avatar
    Fabio Akita Thu, 29 Jun 2006 21: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.