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
validates :first_name, presence: true
validates :last_name, presence: true
validates :slogan, uniqueness: true, presence: true
belongs_to :position
has_many :votes
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 @@
#
# 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|
t.string "first_name"
......@@ -27,8 +27,11 @@ ActiveRecord::Schema.define(version: 20160718023237) do
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "candidate_id"
end
add_index "positions", ["candidate_id"], name: "index_positions_on_candidate_id"
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......@@ -51,6 +54,11 @@ ActiveRecord::Schema.define(version: 20160718023237) do
t.text "comments"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "candidate_id"
end
add_index "votes", ["candidate_id"], name: "index_votes_on_candidate_id"
add_index "votes", ["user_id"], name: "index_votes_on_user_id"
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