adds poll::final_recounts
This commit is contained in:
19
app/models/poll/final_recount.rb
Normal file
19
app/models/poll/final_recount.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Poll
|
||||
class FinalRecount < ActiveRecord::Base
|
||||
belongs_to :booth_assignment, class_name: "Poll::BoothAssignment"
|
||||
belongs_to :officer_assignment, class_name: "Poll::OfficerAssignment"
|
||||
|
||||
validates :booth_assignment_id, presence: true
|
||||
validates :officer_assignment_id, presence: true, uniqueness: {scope: :booth_assignment_id}
|
||||
validates :count, presence: true, numericality: {only_integer: true}
|
||||
|
||||
before_save :update_logs
|
||||
|
||||
def update_logs
|
||||
if self.count_changed? && self.count_was.present?
|
||||
self.count_log += ":#{self.count_was.to_s}"
|
||||
self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
db/migrate/20170130101121_create_poll_final_recount.rb
Normal file
15
db/migrate/20170130101121_create_poll_final_recount.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class CreatePollFinalRecount < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :poll_final_recounts do |t|
|
||||
t.integer :booth_assignment_id
|
||||
t.integer :officer_assignment_id
|
||||
t.integer :count
|
||||
t.text :count_log, default: ""
|
||||
t.datetime :created_at, null: false
|
||||
t.datetime :updated_at, null: false
|
||||
t.text :officer_assignment_id_log, default: ""
|
||||
end
|
||||
|
||||
add_index :poll_final_recounts, :booth_assignment_id
|
||||
end
|
||||
end
|
||||
14
db/schema.rb
14
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: 20170128214244) do
|
||||
ActiveRecord::Schema.define(version: 20170130101121) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -398,6 +398,18 @@ ActiveRecord::Schema.define(version: 20170128214244) do
|
||||
t.string "location"
|
||||
end
|
||||
|
||||
create_table "poll_final_recounts", force: :cascade do |t|
|
||||
t.integer "booth_assignment_id"
|
||||
t.integer "officer_assignment_id"
|
||||
t.integer "count"
|
||||
t.text "count_log", default: ""
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "officer_assignment_id_log", default: ""
|
||||
end
|
||||
|
||||
add_index "poll_final_recounts", ["booth_assignment_id"], name: "index_poll_final_recounts_on_booth_assignment_id", using: :btree
|
||||
|
||||
create_table "poll_officer_assignments", force: :cascade do |t|
|
||||
t.integer "booth_assignment_id"
|
||||
t.integer "officer_id"
|
||||
|
||||
Reference in New Issue
Block a user