Add association between polls and budgets

This commit is contained in:
rgarcia
2018-06-04 20:00:09 +02:00
committed by Javi Martín
parent d3660d1245
commit 20a3f6539d
4 changed files with 11 additions and 0 deletions

View File

@@ -21,6 +21,8 @@ class Budget < ActiveRecord::Base
has_many :headings, through: :groups
has_many :phases, class_name: Budget::Phase
has_one :poll
before_validation :sanitize_descriptions
after_create :generate_phases

View File

@@ -23,6 +23,7 @@ class Poll < ActiveRecord::Base
has_and_belongs_to_many :geozones
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
belongs_to :budget
validates_translation :name, presence: true
validate :date_range

View File

@@ -0,0 +1,5 @@
class AddBudgetToPolls < ActiveRecord::Migration
def change
add_reference :polls, :budget, index: { unique: true }, foreign_key: true
end
end

View File

@@ -1129,8 +1129,10 @@ ActiveRecord::Schema.define(version: 20190205131722) do
t.boolean "stats_enabled", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "budget_id"
end
add_index "polls", ["budget_id"], name: "index_polls_on_budget_id", unique: true, using: :btree
add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree
create_table "progress_bar_translations", force: :cascade do |t|
@@ -1614,6 +1616,7 @@ ActiveRecord::Schema.define(version: 20190205131722) do
add_foreign_key "poll_recounts", "poll_booth_assignments", column: "booth_assignment_id"
add_foreign_key "poll_recounts", "poll_officer_assignments", column: "officer_assignment_id"
add_foreign_key "poll_voters", "polls"
add_foreign_key "polls", "budgets"
add_foreign_key "proposals", "communities"
add_foreign_key "related_content_scores", "related_contents"
add_foreign_key "related_content_scores", "users"