diff --git a/app/models/poll.rb b/app/models/poll.rb index 482b0cf0f..13f926f1c 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,4 +1,6 @@ class Poll < ActiveRecord::Base + has_many :booth_assigments + has_many :booths, through: :booth_assigments, class_name: "Poll::BoothAssignment" has_many :voters, through: :booths, class_name: "Poll::Voter" has_many :officers, through: :booths, class_name: "Poll::Officer" has_many :questions diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index ba9b1f47c..e5589391b 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -1,5 +1,7 @@ class Poll class Booth < ActiveRecord::Base + has_many :booth_assigments + has_many :polls, through: :booth_assigments has_many :voters has_many :officing_booths, dependent: :destroy has_many :officers, through: :officing_booths diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb new file mode 100644 index 000000000..152f3ffb0 --- /dev/null +++ b/app/models/poll/booth_assignment.rb @@ -0,0 +1,6 @@ +class Poll + class BoothAssignment < ActiveRecord::Base + belongs_to :booth + belongs_to :poll + end +end diff --git a/db/migrate/20161130123347_create_poll_booth_assignments.rb b/db/migrate/20161130123347_create_poll_booth_assignments.rb new file mode 100644 index 000000000..36a2b9d64 --- /dev/null +++ b/db/migrate/20161130123347_create_poll_booth_assignments.rb @@ -0,0 +1,9 @@ +class CreatePollBoothAssignments < ActiveRecord::Migration + def change + create_table :poll_booth_assignments do |t| + t.integer :booth_id + t.integer :poll_id + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 78150e6e7..9f180a5f4 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: 20161130122604) do +ActiveRecord::Schema.define(version: 20161130123347) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -278,6 +278,13 @@ ActiveRecord::Schema.define(version: 20161130122604) do add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree + create_table "poll_booth_assignments", force: :cascade do |t| + t.integer "booth_id" + t.integer "poll_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "poll_booths", force: :cascade do |t| t.string "name" t.string "location"