Add ballot_lines_count counter_cache to ballot -> ballot line relationship

This commit is contained in:
Bertocq
2017-06-28 23:50:28 +02:00
committed by Javi Martín
parent 71fd3657d3
commit 63631f29a8
3 changed files with 10 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
class Budget
class Ballot
class Line < ApplicationRecord
belongs_to :ballot
belongs_to :ballot, counter_cache: :ballot_lines_count
belongs_to :investment, counter_cache: :ballot_lines_count
belongs_to :heading
belongs_to :group

View File

@@ -0,0 +1,5 @@
class AddBallotLineCounterCachedToBudgetBallots < ActiveRecord::Migration
def change
add_column :budget_ballots, :ballot_lines_count, :integer, default: 0
end
end

View File

@@ -131,9 +131,10 @@ ActiveRecord::Schema.define(version: 20190411090023) do
create_table "budget_ballots", force: :cascade do |t|
t.integer "user_id"
t.integer "budget_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "physical", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "ballot_lines_count", default: 0
t.boolean "physical", default: false
t.integer "poll_ballot_id"
end