Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Created June 24, 2011 16:23
Show Gist options
  • Save DanielVartanov/1045128 to your computer and use it in GitHub Desktop.
Save DanielVartanov/1045128 to your computer and use it in GitHub Desktop.
require "activerecord"
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "test.sqlite"
class CategoriesMigration < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.string :type
end
end
def self.down
drop_table :categories
end
end
CategoriesMigration.migrate :up
class Category < ActiveRecord::Base
end
class Subcategory < Category
end
Category.create! :name => "Root"
Subcategory.create! :name => "Leaf"
puts Category.last.inspect # => #<Subcategory id: 2, name: "Leaf", type: "Subcategory">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment