Commit b131b536 authored by Bianca Tarun's avatar Bianca Tarun

edited models and added foreign keys

parent aa32fd71
...@@ -2,4 +2,6 @@ class Candidate < ActiveRecord::Base ...@@ -2,4 +2,6 @@ class Candidate < ActiveRecord::Base
validates :first_name, presence: true validates :first_name, presence: true
validates :last_name, presence: true validates :last_name, presence: true
validates :slogan, uniqueness: true, presence: true validates :slogan, uniqueness: true, presence: true
belongs_to :position
has_many :votes
end end
class AddUserToVotes < ActiveRecord::Migration
def change
add_reference :votes, :user, index: true, foreign_key: true
end
end
class AddCandidateToVotes < ActiveRecord::Migration
def change
add_reference :votes, :candidate, index: true, foreign_key: true
end
end
class AddCandidateToPositions < ActiveRecord::Migration
def change
add_reference :positions, :candidate, index: true, foreign_key: true
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160718023237) do ActiveRecord::Schema.define(version: 20160718031721) do
create_table "candidates", force: :cascade do |t| create_table "candidates", force: :cascade do |t|
t.string "first_name" t.string "first_name"
...@@ -25,10 +25,13 @@ ActiveRecord::Schema.define(version: 20160718023237) do ...@@ -25,10 +25,13 @@ ActiveRecord::Schema.define(version: 20160718023237) do
create_table "positions", force: :cascade do |t| create_table "positions", force: :cascade do |t|
t.string "name" t.string "name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "candidate_id"
end end
add_index "positions", ["candidate_id"], name: "index_positions_on_candidate_id"
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
...@@ -49,8 +52,13 @@ ActiveRecord::Schema.define(version: 20160718023237) do ...@@ -49,8 +52,13 @@ ActiveRecord::Schema.define(version: 20160718023237) do
create_table "votes", force: :cascade do |t| create_table "votes", force: :cascade do |t|
t.text "comments" t.text "comments"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "candidate_id"
end end
add_index "votes", ["candidate_id"], name: "index_votes_on_candidate_id"
add_index "votes", ["user_id"], name: "index_votes_on_user_id"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment