class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
class Person < ActiveRecord::Base
has_many :addresses, :as => :addressable
end
class Company < ActiveRecord::Base
has_many :addresses, :as => :addressable
end
>> c = Company.create(:name => "WidgetCo")
>> p = Person.create(:name => "John Smith")
>> a1 = Address.create(:street => "123 Foo ST", :city => "Barville", :state_code => "MT", :zip_code => "12345", :addressable => p)
>> a2 = Address.create(:street => "321 Contact RD", :city => "Bazburg", :state_code => "MT", :zip_code => "54321", :addressable => c)
>> Address.all(:conditions => { :addressable_type => Person.class_name })
=> [#<Address id: 1, street: "123 Foo ST" ... >]