Created
April 20, 2016 15:30
-
-
Save stevecass/114c8e498393fceaeb31f21eb0e95982 to your computer and use it in GitHub Desktop.
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 Post < ActiveRecord::Base | |
has_many :comments, as: :commentable | |
end | |
class Photo < ActiveRecord::Base | |
has_many :comments, as: :commentable | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :commentable, polymorphic: true | |
end | |
class CreatePosts < ActiveRecord::Migration | |
def change | |
create_table :posts do |t| | |
t.integer :user_id, index: true | |
t.string :title | |
t.text :body | |
t.string :publication_status | |
t.date :published_on | |
end | |
create_table :photos do |t| | |
t.integer :post_id, index: true | |
t.string :caption | |
end | |
create_table :comments do |t| | |
t.references :commentable, polymorphic: true, index: true | |
t.integer :user_id, index: true | |
t.string :body | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment