Skip to content

Instantly share code, notes, and snippets.

@risen
Created November 5, 2015 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save risen/b5a76d0929379303af30 to your computer and use it in GitHub Desktop.
Save risen/b5a76d0929379303af30 to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.require
class Product < ActiveRecord::Base
actable
belongs_to :pen_case
end
class Pen < ActiveRecord::Base
acts_as :product
end
class PenCase < ActiveRecord::Base
acts_as :product
has_many :products
end
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.actable
t.references :pen_case
t.string :name
t.decimal :price
end
end
end
class CreatePens < ActiveRecord::Migration
def change
create_table :pens do |t|
t.string :color
end
end
end
class CreatePenCases < ActiveRecord::Migration
def change
create_table :pen_cases do |t|
t.integer :capacity
end
end
end
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db.sqlite3')
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.logger.level = Logger::INFO
ActiveRecord::Migration.verbose = true
ActiveRecord::Migration.descendants.each { |m| m.migrate(:up) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment