From 1d1b861ddf34e7caaf68077c9a6e4dc571acd3aa Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Tue, 3 Oct 2017 23:04:50 -0400 Subject: [PATCH] Create 'poll_question_answers' table --- app/models/poll/question.rb | 1 + app/models/poll/question_answer.rb | 5 +++++ .../20171004025903_create_poll_question_answers.rb | 9 +++++++++ db/schema.rb | 11 ++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/models/poll/question_answer.rb create mode 100644 db/migrate/20171004025903_create_poll_question_answers.rb diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index a46f28a8c..d576ac95a 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -15,6 +15,7 @@ class Poll::Question < ActiveRecord::Base has_many :comments, as: :commentable has_many :answers + has_many :question_answers, class_name: 'Poll::QuestionAnswer', foreign_key: 'poll_question_id' has_many :partial_results belongs_to :proposal diff --git a/app/models/poll/question_answer.rb b/app/models/poll/question_answer.rb new file mode 100644 index 000000000..508a92ee2 --- /dev/null +++ b/app/models/poll/question_answer.rb @@ -0,0 +1,5 @@ +class Poll::QuestionAnswer < ActiveRecord::Base + belongs_to :question, class_name: 'Poll::Question', foreign_key: 'poll_question_id' + + validates :title, presence: true +end diff --git a/db/migrate/20171004025903_create_poll_question_answers.rb b/db/migrate/20171004025903_create_poll_question_answers.rb new file mode 100644 index 000000000..834421f5f --- /dev/null +++ b/db/migrate/20171004025903_create_poll_question_answers.rb @@ -0,0 +1,9 @@ +class CreatePollQuestionAnswers < ActiveRecord::Migration + def change + create_table :poll_question_answers do |t| + t.string :title + t.text :description + t.references :poll_question, index: true, foreign_key: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index af121fa0e..4e62c099c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171002191347) do +ActiveRecord::Schema.define(version: 20171004025903) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -669,6 +669,14 @@ ActiveRecord::Schema.define(version: 20171002191347) do add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree + create_table "poll_question_answers", force: :cascade do |t| + t.string "title" + t.text "description" + t.integer "poll_question_id" + end + + add_index "poll_question_answers", ["poll_question_id"], name: "index_poll_question_answers_on_poll_question_id", using: :btree + create_table "poll_questions", force: :cascade do |t| t.integer "proposal_id" t.integer "poll_id" @@ -1143,6 +1151,7 @@ ActiveRecord::Schema.define(version: 20171002191347) do add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_partial_results", "poll_questions", column: "question_id" add_foreign_key "poll_partial_results", "users", column: "author_id" + add_foreign_key "poll_question_answers", "poll_questions" add_foreign_key "poll_questions", "polls" add_foreign_key "poll_questions", "proposals" add_foreign_key "poll_questions", "users", column: "author_id"