1
0
Fork 0

Setup models for friends

This commit is contained in:
Andrew Tomaka 2014-10-15 13:17:36 -04:00
parent 34ec10189c
commit 1752dffb95
4 changed files with 25 additions and 1 deletions

4
app/models/friendship.rb Normal file
View File

@ -0,0 +1,4 @@
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: 'User'
end

View File

@ -1,4 +1,7 @@
class User < ActiveRecord::Base
has_many :friendships
has_many :friends, through: :friendships
def self.from_omniauth(auth)
where(provider: auth[:provider], uid: auth[:uid]).first_or_create do |user|
user.provider = auth[:provider]

View File

@ -0,0 +1,10 @@
class CreateFriendships < ActiveRecord::Migration
def change
create_table :friendships do |t|
t.integer :user_id
t.integer :friend_id
t.timestamps
end
end
end

View File

@ -11,7 +11,14 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141002202749) do
ActiveRecord::Schema.define(version: 20141015144022) do
create_table "friendships", force: true do |t|
t.integer "user_id"
t.integer "friend_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: true do |t|
t.string "provider"