Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## Models class Account < ActiveRecord::Base has_many :users, :as => :account, :dependent => :destroy end class Buyer < Account set_table_name :buyers end class Seller < Account set_table_name :sellers end class User < ActiveRecord::Base belongs_to :account, :polymorphic => true end ## Tables (minimal fields for testing) create_table :users do |t| t.references :account, :polymorphic => true t.string :name end create_table :buyers do |t| t.string :company end create_table :sellers do |t| t.string :organization end ## Console: Loading development environment (Rails 2.0.2) >> b = Buyer.create(:company => "FooCo") => #<Buyer id: 1, company: "FooCo"> >> b.users << User.new(:name => "Joe User") => [#<User id: 1, account_id: 1, account_type: "Buyer", name: "Joe User">] >> s = Seller.create(:organization => "BarOrg") => #<Seller id: 1, organization: "BarOrg"> >> s.users << User.new(:name => "Sam OtherUser") => [#<User id: 2, account_id: 1, account_type: "Seller", name: "Sam OtherUser">] >> User.find(:first).account => #<Buyer id: 1, company: "FooCo"> >> User.find(:first).account.users => [#<User id: 1, account_id: 1, account_type: "Buyer", name: "Joe User">] >> User.find(:first).account.class => Buyer(id: integer, company: string) >>
This paste will be private.
From the Design Piracy series on my blog: