Created
June 24, 2011 16:23
-
-
Save DanielVartanov/1045128 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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