Last active
February 16, 2017 15:48
-
-
Save Chryus/c1e258af03626648b242a375892c60a8 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
# graffiti.rb | |
class Graffiti < ActiveRecord::Base | |
has_many :uploads | |
has_many :upvotes, as: :upvotable | |
end | |
# upload.rb | |
class Upload < ApplicationRecord | |
belongs_to :user | |
belongs_to :graffiti | |
has_many :upvotes, as: :upvotable | |
end | |
# upvote.rb | |
class Upvote < ApplicationRecord | |
belongs_to :user | |
belongs_to :upvotable, polymorphic: true | |
end | |
# schema | |
create_table :upvotes do |t| | |
t.integer :user_id | |
t.integer :upvotable_id | |
t.string :upvotable_type | |
t.timestamps | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment