Created
September 4, 2011 15:24
-
-
Save tbaba/1193011 to your computer and use it in GitHub Desktop.
Single Table Inheritance Sample
This file contains 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
class CreateArticles < ActiveRecord::Migration | |
self.up | |
create_table :articles do |t| | |
t.string :title | |
t.text :body | |
t.string :type | |
t.timestamps | |
end | |
end | |
self.down | |
drop_table :articles | |
end | |
end |
This file contains 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
# article.rb | |
class Article < ActiveRecord::Base | |
end | |
# post.rb | |
class Post < Article | |
end | |
# page.rb | |
class Page < Article | |
end | |
--- | |
> Post.all | |
=> [<Post>, <Post>] | |
> Page.all | |
=> [<Page>, <Page>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment