adds poll_id and stats fields to poll_voters
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
class Poll
|
class Poll
|
||||||
class Voter < ActiveRecord::Base
|
class Voter < ActiveRecord::Base
|
||||||
belongs_to :booth_assignment
|
belongs_to :booth_assignment
|
||||||
delegate :poll, to: :booth_assignment
|
belongs_to :poll
|
||||||
|
|
||||||
validates :booth_assignment, presence: true
|
validates :booth_assignment, presence: true
|
||||||
validate :in_census
|
validate :in_census
|
||||||
validate :has_not_voted
|
validate :has_not_voted
|
||||||
|
validates :poll, presence: true
|
||||||
|
validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type] }
|
||||||
|
|
||||||
def in_census
|
def in_census
|
||||||
errors.add(:document_number, :not_in_census) unless census_api_response.valid?
|
errors.add(:document_number, :not_in_census) unless census_api_response.valid?
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
class AddPollIdAndStatsFieldsToPollVoter < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :poll_voters, :poll_id, :integer, null: false
|
||||||
|
|
||||||
|
remove_column :poll_voters, :booth_assignment_id, :integer, null: false
|
||||||
|
add_column :poll_voters, :booth_assignment_id, :integer
|
||||||
|
|
||||||
|
add_column :poll_voters, :age, :integer
|
||||||
|
add_column :poll_voters, :gender, :string
|
||||||
|
add_column :poll_voters, :geozone_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -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: 20170120164547) do
|
ActiveRecord::Schema.define(version: 20170125104542) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -449,9 +449,13 @@ ActiveRecord::Schema.define(version: 20170120164547) do
|
|||||||
create_table "poll_voters", force: :cascade do |t|
|
create_table "poll_voters", force: :cascade do |t|
|
||||||
t.string "document_number"
|
t.string "document_number"
|
||||||
t.string "document_type"
|
t.string "document_type"
|
||||||
t.integer "booth_assignment_id", null: false
|
|
||||||
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 "poll_id", null: false
|
||||||
|
t.integer "booth_assignment_id"
|
||||||
|
t.integer "age"
|
||||||
|
t.string "gender"
|
||||||
|
t.integer "geozone_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "polls", force: :cascade do |t|
|
create_table "polls", force: :cascade do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user