Last active
February 16, 2017 15:23
-
-
Save Chryus/8231e5d7804b192bd86510f9f548a8bd 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
# user.rb | |
class User < ActiveRecord::Base | |
has_many :upvotes | |
has_many :graffiti, through: :upvotes | |
end | |
# graffiti.rb | |
class Graffiti < ActiveRecord::Base | |
has_many :upvotes | |
has_many :users, through: :upvotes | |
end | |
# upvote.rb | |
class Upvote < ApplicationRecord | |
belongs_to :user | |
belongs_to :graffiti | |
end | |
# schema | |
create_table "upvotes", force: :cascade do |t| | |
t.integer "user_id" | |
t.integer "graffiti_id" | |
t.timestamps | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment