Sneaking Rails through the (Legacy) system 4
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
- Sneaking Rails through the (Legacy) System (quicktime)
- Sneaking Rails through the (Legacy) System (flash)
...Jeremy posted his slides as well. :-)
Enjoying the content? Be sure to subscribe to my RSS feed.





Hey Robby,
Is the code for this available anywhere?
has commenting been fixed yet?
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.
intresting article! thnks