Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active February 16, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chryus/8231e5d7804b192bd86510f9f548a8bd to your computer and use it in GitHub Desktop.
Save Chryus/8231e5d7804b192bd86510f9f548a8bd to your computer and use it in GitHub Desktop.
# 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