Skip to content

Commit

Permalink
Merge branch '26-user-db-releationship' of https://github.com/jamesha…
Browse files Browse the repository at this point in the history
…mann/pict into 26-user-db-releationship
  • Loading branch information
jameshamann committed Nov 13, 2016
2 parents f94f65b + 3aced38 commit af6a16a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/models/comment.rb
@@ -1,5 +1,6 @@
class Comment < ApplicationRecord

belongs_to :photo
belongs_to :user
has_one :photo

end
3 changes: 2 additions & 1 deletion app/models/photo.rb
@@ -1,5 +1,6 @@
class Photo < ApplicationRecord
has_attached_file :avatar, styles: { medium: "300x300>"}, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\z/
has_many :comments
has_many :comments, dependent: :destroy
belongs_to :user
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Expand Up @@ -11,4 +11,8 @@ def self.from_omniauth(auth)
user.name = auth.info.name # assuming the user model has a name
end
end

has_many :comments, dependent: :destroy
has_many :photos, dependent: :destroy

end
5 changes: 5 additions & 0 deletions db/migrate/20161109215925_add_user_ref_to_comments.rb
@@ -0,0 +1,5 @@
class AddUserRefToComments < ActiveRecord::Migration[5.0]
def change
add_reference :comments, :user, foreign_key: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20161109220038_add_user_ref_to_photos.rb
@@ -0,0 +1,5 @@
class AddUserRefToPhotos < ActiveRecord::Migration[5.0]
def change
add_reference :photos, :user, foreign_key: true
end
end
22 changes: 7 additions & 15 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161109122001) do
ActiveRecord::Schema.define(version: 20161109220038) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -20,6 +20,8 @@
t.integer "photo_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["user_id"], name: "index_comments_on_user_id", using: :btree
end

create_table "photos", force: :cascade do |t|
Expand All @@ -31,6 +33,8 @@
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "user_id"
t.index ["user_id"], name: "index_photos_on_user_id", using: :btree
end

create_table "users", force: :cascade do |t|
Expand All @@ -53,18 +57,6 @@
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end

create_table "votes", force: :cascade do |t|
t.string "votable_type"
t.integer "votable_id"
t.string "voter_type"
t.integer "voter_id"
t.boolean "vote_flag"
t.string "vote_scope"
t.integer "vote_weight"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
t.index ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
end

add_foreign_key "comments", "users"
add_foreign_key "photos", "users"
end

0 comments on commit af6a16a

Please sign in to comment.